In table i have column 'description' , which contain description of goods. I want include in CGridView column 'short_description', which will contain first 150 characters.
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);
}
Unfortunately, this code does not work .
You need to override afterFind function of model class and write the code
$this->short_description = substr($this->description, 0, 150);
in afterFind function.
You need to do some thing like this
protected function afterFind()
{
parent::afterFind();
$this->short_description = substr($this->description, 0, 150);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With