小编Dar*_*eMD的帖子

使用Yii框架在模型类中添加新字段

在表格中,我有列'描述',其中包含商品描述.我希望在CGridView列中包含'short_description',它将包含前150个字符.

class Product extends CActiveRecord
{   
    /**
     * The followings are the available columns in table 'Product':
     * @var integer $id
     * @var integer $id_cat
     * @var string $title
     * @var string $description
     * @var timestamp $date
     */
    public $id;
    public $id_cat;
    public $title;
    public $description;
    public $date;
    public $short_description ;

    public function init()
    {
        $this->short_description = substr($this->description, 0, 150);     
    }
Run Code Online (Sandbox Code Playgroud)

不幸的是,这段代码不起作用.

php yii

3
推荐指数
1
解决办法
7406
查看次数

标签 统计

php ×1

yii ×1