Issue
I am trying to access attributes of the model in the view and it is throwing me the error mentioned in the title. This is my CompanyMask
model:
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(
'company' => array(self::BELONGS_TO, 'company', 'company_id'),
);
}
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria = new CDbCriteria;
// $criteria->select = "t.id, t.company_id, t.mask_id, t.mask_text, c.name as company_name";
// $criteria->join = 'LEFT JOIN company c on c.id=t.company_id';
$criteria->with = array('company');
$criteria->compare('id', $this->id);
$criteria->compare('company_id', $this->company_id);
$criteria->compare('mask_id', $this->mask_id);
$criteria->compare('mask_text', $this->mask_text, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
Now In the view I am trying to access the name of the company like this:
$gridView = $this->widget('zii.widgets.grid.CGridView', array(
'id' => 'deals-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'ajaxUpdate' => 'deals-grid',
'itemsCssClass' => 'table table-striped table-responsive table-bordered no-margin',
'pagerCssClass' => 'pagination pagination-sm no-margin pull-right',
'pager' => array(
'maxButtonCount' => '7',
),
'columns' => array(
array(
'header' => 'Company Name',
'type' => 'raw',
'htmlOptions' => array('style' => 'width:15%',),
'value' => '$data->company->name',
),
),
));
What am I doing wrong here? Any help?
Solution
It's about two things:
- You are using
$data
as object, but it's an array:$data['company']->name
- You are using single quotes, so the
value
is the literal value$data->company->name
instead of the real value. Remove the single quotes around$data['company']->name
Answered By - schellingerht
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.