2017-05-24 4 views
0

ビューのモデルの属性にアクセスしようとしていますが、タイトルに記載されているエラーが表示されています。私はこのような会社の名前にアクセスしようとしていますビューで、今Yii:ビュー内で非オブジェクトのプロパティを取得しようとしています

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, 
     )); 
    } 

::これは私のCompanyMaskモデルです

$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', 
         ), 

        ), 
       )); 

私はここで間違って何をしているのですか?どんな助け?

+0

私は '$ data'が配列だと思います – ArtOsi

+0

ああ、あなたは私の一日を保存しました!本当にありがとう! – Saani

答えて

1

約2のものです:

  1. あなたがオブジェクトとして$dataを使用しているが、それは、配列です:$data['company']->name
  2. あなたは、単一引用符を使用しているので、valueリテラル値$data->company->nameの代わりに、実際の値であり、 。一重引用符を削除する$data['company']->name
関連する問題