在表格中,我有列'描述',其中包含商品描述.我希望在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)
不幸的是,这段代码不起作用.