I written a relation in my model somewhat like this
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(
'category' => array(self::BELONGS_TO, 'Category', 'categoryid'),
'company' => array(self::BELONGS_TO, 'CommercialUser', 'createdby'),
'subcategory' => array(self::BELONGS_TO, 'SubCategory', 'subcategory'),
);
}
and I created a view page with subcategory field and called it by array
my View
<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
//'id',
array(
'name' => 'type',
'type' => 'raw',
value'=>$model->type
),
'title',
'description',
array(
'name' => 'Category',
'type' => 'raw',
'value'=>$model->category->categoryname
),
'subcategory',
array(
'name' => 'subcategory',
'type' => 'raw',
'value'=>$model->subcategory->subcategory_name
),
'location',
'startdate',
'enddate',
array(
'name' => 'image',
'type' => 'raw',
'value'=>GFunctions::GetoffereveImage($model->id)
),
),
)); ?>
And I Have table called sub_category in my DB
All i need is to make relation to that table to get the subcategory_name...
When I tried it is showing me an Error like
Trying to get property of non-object
Please somebody help me to fix this...
Thank you