【发布时间】:2017-05-24 12:38:28
【问题描述】:
我试图在视图中访问模型的属性,它向我抛出了标题中提到的错误。这是我的CompanyMask 模型:
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,
));
}
现在,在视图中,我正尝试像这样访问公司的名称:
$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',
),
),
));
我在这里做错了什么?有什么帮助吗?
【问题讨论】:
-
我认为
$data是一个数组 -
天哪,你救了我的命!非常感谢!