I have a category table with an ID and a parentID in order to have sub-categories.
I would like to display the description of the sub-category in the CGridView.
I have the following code:
in the model
public $parentName;
public function rules()
{
...
array('id, name, parentID, parentName, position, active, pageContent', 'safe', 'on'=>'search'),
...
}
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
...
'selfParent' => array(self::BELONGS_TO, 'Category', 'parentID'),
);
}
public function search() {
...
$criteria->together = true;
$criteria->with = array('selfParent');
if($this->parentName)
{
$criteria->compare('selfParent.name', $this->parentName, true);
}
}
then in the view, i have the following code:
array(
'name'=>'parentName',
'value' => '$data->selfParent->name',
),
But this gives an error "Trying to get property of non-object "
Can somebody help me out of the woods?