Yii框架学习 4-3 使用Getter和Setter 获取和定义 model 属性

表model类中
    //Getter方法 处理content字段
    public function getContentText(){
        $tmp = strip_tags($this->content);
        $temLen = mb_strlen($tmp);
        return mb_substr($tmp,0,20,'utf-8').(($temLen>20)?'...':"");
    }

view index页面使用
            [
                'attribute'=>'content',
//                'value'=>function($model){
//                    $tmp = strip_tags($model->content);
//                    $temLen = mb_strlen($tmp);
//                    return mb_substr($tmp,0,20,'utf-8').(($temLen>20)?'...':"");
//                }
                'value'=>'contentText'
            ],

原文地址:https://www.cnblogs.com/gaogaoxingxing/p/12745288.html