2012-08-30 53 views
0

在Yii框架與CGridView我需要從的CActiveRecord的CActiveRecord和「試圖獲得非對象的屬性」錯誤

讀取值

列定義CGridView是列:

'columns'=>array(
     .... 
     array(
      'name'=>'rel_CustomerCampain.event_comment', 
      'header'=>'Commenti Camp.', 
      'value'=>'print_r($data->rel_CustomerCampain,false)' 
     ), 
..... 

我有這樣的對象$數據 - > rel_CustomerCampain,我需要有下的event_comment值 「_attributes:的CActiveRecord:私人」 的值: *IneedOfThisValue**

當我嘗試 '值'=> '$數據 - > rel_CustomerCampain-> event_comment'

我有這樣的錯誤: 「試圖獲得非對象的屬性」

有沒有想法? 在此先感謝....

[0] => customerCampain Object 
     (
      [_md:CActiveRecord:private] => CActiveRecordMetaData Object 
       (
        [tableSchema] => CMysqlTableSchema Object 
         (
          [schemaName] => 
          [name] => tbl_customer_campain 
          [rawName] => `tbl_customer_campain` 
          [primaryKey] => id 
          [sequenceName] => 
          [foreignKeys] => Array 
           (
            [id_campain] => Array 
             (
              [0] => tbl_campain 
              [1] => id 
             ) 

            [id_customer] => Array 
             (
              [0] => tbl_customer 
              [1] => id 
             ) 

           ) 

          [columns] => Array 
           (
            [id] => CMysqlColumnSchema Object 
             (
              [name] => id 
              [rawName] => `id` 
              [allowNull] => 
              [dbType] => int(10) unsigned 
              [type] => string 
              [defaultValue] => 
              [size] => 10 
              [precision] => 10 
              [scale] => 
              [isPrimaryKey] => 1 
              [isForeignKey] => 
              [autoIncrement] => 1 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [id_campain] => CMysqlColumnSchema Object 
             (
              [name] => id_campain 
              [rawName] => `id_campain` 
              [allowNull] => 
              [dbType] => int(10) unsigned 
              [type] => string 
              [defaultValue] => 
              [size] => 10 
              [precision] => 10 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 1 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [id_customer] => CMysqlColumnSchema Object 
             (
              [name] => id_customer 
              [rawName] => `id_customer` 
              [allowNull] => 
              [dbType] => int(10) unsigned 
              [type] => string 
              [defaultValue] => 
              [size] => 10 
              [precision] => 10 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 1 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [event_datetime] => CMysqlColumnSchema Object 
             (
              [name] => event_datetime 
              [rawName] => `event_datetime` 
              [allowNull] => 1 
              [dbType] => datetime 
              [type] => string 
              [defaultValue] => 
              [size] => 
              [precision] => 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [event_type] => CMysqlColumnSchema Object 
             (
              [name] => event_type 
              [rawName] => `event_type` 
              [allowNull] => 1 
              [dbType] => varchar(200) 
              [type] => string 
              [defaultValue] => 
              [size] => 200 
              [precision] => 200 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [event_status] => CMysqlColumnSchema Object 
             (
              [name] => event_status 
              [rawName] => `event_status` 
              [allowNull] => 1 
              [dbType] => varchar(200) 
              [type] => string 
              [defaultValue] => 
              [size] => 200 
              [precision] => 200 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

            [event_comment] => CMysqlColumnSchema Object 
             (
              [name] => event_comment 
              [rawName] => `event_comment` 
              [allowNull] => 1 
              [dbType] => text 
              [type] => string 
              [defaultValue] => 
              [size] => 
              [precision] => 
              [scale] => 
              [isPrimaryKey] => 
              [isForeignKey] => 
              [autoIncrement] => 
              [_e:CComponent:private] => 
              [_m:CComponent:private] => 
             ) 

           ) 

          [_e:CComponent:private] => 
          [_m:CComponent:private] => 
         ) 

        [columns] => Array 
         (
          [id] => CMysqlColumnSchema Object 
           (
            [name] => id 
            [rawName] => `id` 
            [allowNull] => 
            [dbType] => int(10) unsigned 
            [type] => string 
            [defaultValue] => 
            [size] => 10 
            [precision] => 10 
            [scale] => 
            [isPrimaryKey] => 1 
            [isForeignKey] => 
            [autoIncrement] => 1 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [id_campain] => CMysqlColumnSchema Object 
           (
            [name] => id_campain 
            [rawName] => `id_campain` 
            [allowNull] => 
            [dbType] => int(10) unsigned 
            [type] => string 
            [defaultValue] => 
            [size] => 10 
            [precision] => 10 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 1 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [id_customer] => CMysqlColumnSchema Object 
           (
            [name] => id_customer 
            [rawName] => `id_customer` 
            [allowNull] => 
            [dbType] => int(10) unsigned 
            [type] => string 
            [defaultValue] => 
            [size] => 10 
            [precision] => 10 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 1 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [event_datetime] => CMysqlColumnSchema Object 
           (
            [name] => event_datetime 
            [rawName] => `event_datetime` 
            [allowNull] => 1 
            [dbType] => datetime 
            [type] => string 
            [defaultValue] => 
            [size] => 
            [precision] => 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [event_type] => CMysqlColumnSchema Object 
           (
            [name] => event_type 
            [rawName] => `event_type` 
            [allowNull] => 1 
            [dbType] => varchar(200) 
            [type] => string 
            [defaultValue] => 
            [size] => 200 
            [precision] => 200 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [event_status] => CMysqlColumnSchema Object 
           (
            [name] => event_status 
            [rawName] => `event_status` 
            [allowNull] => 1 
            [dbType] => varchar(200) 
            [type] => string 
            [defaultValue] => 
            [size] => 200 
            [precision] => 200 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [event_comment] => CMysqlColumnSchema Object 
           (
            [name] => event_comment 
            [rawName] => `event_comment` 
            [allowNull] => 1 
            [dbType] => text 
            [type] => string 
            [defaultValue] => 
            [size] => 
            [precision] => 
            [scale] => 
            [isPrimaryKey] => 
            [isForeignKey] => 
            [autoIncrement] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

         ) 

        [relations] => Array 
         (
          [relCustomer] => CBelongsToRelation Object 
           (
            [joinType] => LEFT OUTER JOIN 
            [on] => 
            [alias] => 
            [with] => Array 
             (
             ) 

            [together] => 
            [scopes] => 
            [name] => relCustomer 
            [className] => customer 
            [foreignKey] => id_customer 
            [select] => * 
            [condition] => 
            [params] => Array 
             (
             ) 

            [group] => 
            [join] => 
            [having] => 
            [order] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

          [idCampain] => CBelongsToRelation Object 
           (
            [joinType] => LEFT OUTER JOIN 
            [on] => 
            [alias] => 
            [with] => Array 
             (
             ) 

            [together] => 
            [scopes] => 
            [name] => idCampain 
            [className] => TblCampain 
            [foreignKey] => id_campain 
            [select] => * 
            [condition] => 
            [params] => Array 
             (
             ) 

            [group] => 
            [join] => 
            [having] => 
            [order] => 
            [_e:CComponent:private] => 
            [_m:CComponent:private] => 
           ) 

         ) 

        [attributeDefaults] => Array 
         (
         ) 

        [_model:CActiveRecordMetaData:private] => customerCampain Object 
         (
          [_md:CActiveRecord:private] => CActiveRecordMetaData Object 
*RECURSION* 
          [_new:CActiveRecord:private] => 
          [_attributes:CActiveRecord:private] => Array 
           (
           ) 

          [_related:CActiveRecord:private] => Array 
           (
           ) 

          [_c:CActiveRecord:private] => 
          [_pk:CActiveRecord:private] => 
          [_alias:CActiveRecord:private] => t 
          [_errors:CModel:private] => Array 
           (
           ) 

          [_validators:CModel:private] => 
          [_scenario:CModel:private] => 
          [_e:CComponent:private] => 
          [_m:CComponent:private] => 
         ) 

       ) 

      [_new:CActiveRecord:private] => 
      [_attributes:CActiveRecord:private] => Array 
       (
        [id] => 2155 
        [id_campain] => 4 
        [id_customer] => 109 
        [event_datetime] => 
        [event_type] => 
        [event_status] => 
        [event_comment] => ******IneedOfThisValue***** 
       ) 

      [_related:CActiveRecord:private] => Array 
       (
       ) 

      [_c:CActiveRecord:private] => 
      [_pk:CActiveRecord:private] => 2155 
      [_alias:CActiveRecord:private] => t 
      [_errors:CModel:private] => Array 
       (
       ) 

      [_validators:CModel:private] => 
      [_scenario:CModel:private] => update 
      [_e:CComponent:private] => 
      [_m:CComponent:private] => 
     ) 

) 
+1

如果你的關係是HAS_MANY,那麼'rel_CustomerCampain'將是一個數組,那麼爲什麼你得到這個錯誤,你的關係HAS_MANY也是這樣? –

+0

那是什麼print_r輸出? 'print_r($ data)','print_r($ data-> rel_CustomerCampain)',還是別的? – ernie

+0

是print_r($ data-> rel_CustomerCampain,false) –

回答

1

,因爲我是懷疑,當前的模式,即要爲其顯示在GridView的一個,先後與CustomerCampain模型HAS_MANY關係。這意味着$data->rel_CustomerCampainCustomerCampain對象的陣列,這也可以從你的print_r的輸出看出:

[0] => customerCampain Object 
    (
     ... 
    ) 

所以不是:

'value'=>'$data->rel_CustomerCampain->event_comment' 

你要做的:

'value'=>'$data->rel_CustomerCampain[arrayIndex]->event_comment' 
// here arrayIndex will have to be the index of the campain you are interested in 
'value'=>'$data->rel_CustomerCampain[0]->event_comment' // 0 index for the first campain 

(1):首先看comment問題

+0

如果我錯過了任何東西,您可以隨時留下澄清意見 –

相關問題