Reputation: 3322
We have the Categories table with columns: id parent_id title
Also we have the relation:
public function relations()
{
return array(
'Parent' => array(self::BELONGS_TO, 'Categories', 'parent_id'),
);
}
We use the function:
public function getFullCategory()
{
$showparentname = 'Parent.title';
return $this->$showparentname.' - '.$this->title;
}
The form dropDownList use:
$categories = Categories::model()->findAll();
$categories_list = CHtml::listData($categories, 'id', 'FullCategory');
But it doesn't work
Property "Categories.Parent.title" is not defined.
Upvotes: 0
Views: 206
Reputation: 2267
You can't use 'Parent.title', it's triing to get $this->Parent.title property. Use this:
function getTitleWithParent(){
return ( $this->Parent !== null ? $this->Parent->title.' - ' : '' ).$this->title;
}
Upvotes: 1