Trying To Get Property Of Non-Object После Переоса На Хостинг

Здравствуйте

В моей форме


<?php

    echo CHtml::form();

    echo CHtml::submitButton('Подтвердить', array('name'=>'noban'));

    echo CHtml::submitButton('Скрытть', array('name'=>'ban'));

 

    

     $this->widget('zii.widgets.grid.CGridView', array(

	'id'=>'comments-grid',

    'selectableRows' => 2,

	'dataProvider'=>$model->search(),

	'filter'=>$model,

	'columns'=>array(

		'id' => array(

            'name' => 'id',

            'headerHtmlOptions' => array('width'=>30),

        ),

        array(

            'class' => 'CCheckBoxColumn',

            'id' => 'post_id',

        ),

		'status'=> array(

            'name' => 'status',

            'value' => '($data->status==0)?"Не подтвержден":"Подтвержден"',

            'filter' => array(0=>"Не подтвержден",1=>"Подтвержден"),

        ),

		'content',

		'page_id' => array(

            'name' =>  'page_id',

            'value' => '$data->page->title', 

            'filter'=> Page::all(),  

        ),

		'created' => array(

            'name' => 'created',

            'value' => 'date("j.m.Y H:i", $data->created)',

            'filter' => false,

        ),

		'user_id' => array(

            'name' =>  'user_id',

            'value' => '$data->user->username',

            //'value' => '$data->page->title',

            'filter'=> User::all(),  

        ),

		'guest'=> array(

            'name' => 'guest',

            'value' => '($data->guest==0)?" ":"Гость"',

            'filter' => array(0=>"",1=>"Гость"),

        ),

		array(

			'class'=>'CButtonColumn',

            'updateButtonOptions'=> array('style' => 'display:none'),

		),

	),

)); 

echo CHtml::endForm();

?>

При обращении к (на сколько я понял) связанной таблице


'value' => '$data->user->username',

случается ошибка


PHP notice


Trying to get property of non-object


/var/www/html/framework/base/CComponent.php(612) : eval()'d code(1)

Stack Trace

#0 	

+

 /var/www/html/framework/base/CComponent.php(612): eval()

#1 	

+

 /var/www/html/framework/zii/widgets/grid/CDataColumn.php(137): CComponent->evaluateExpression("$data->user->username", array("data" => Comments, "row" => 1))

#2 	

+

 /var/www/html/framework/zii/widgets/grid/CGridColumn.php(151): CDataColumn->renderDataCellContent(1, Comments)

#3 	

+

 /var/www/html/framework/zii/widgets/grid/CGridView.php(616): CGridColumn->renderDataCell(1)

#4 	

+

 /var/www/html/framework/zii/widgets/grid/CGridView.php(572): CGridView->renderTableRow(1)

#5 	

+

 /var/www/html/framework/zii/widgets/grid/CGridView.php(482): CGridView->renderTableBody()

#6 	

+

 /var/www/html/framework/zii/widgets/CBaseListView.php(167): CGridView->renderItems()

#7 	

 unknown(0): CBaseListView->renderSection(array("{items}", "items"))

#8 	

+

 /var/www/html/framework/zii/widgets/CBaseListView.php(150): preg_replace_callback("/{(\w+)}/", array(CGridView, "renderSection"), "{summary} {items} {pager}")

#9 	

+

 /var/www/html/framework/zii/widgets/CBaseListView.php(135): CBaseListView->renderContent()

#10 	

+

 /var/www/html/framework/web/CBaseController.php(173): CBaseListView->run()

#11 	

–

 /var/www/html/cms_hort/protected/modules/admin/views/comments/index.php(85): CBaseController->widget("zii.widgets.grid.CGridView", array("id" => "comments-grid", "selectableRows" => 2, "dataProvider" => CActiveDataProvider, "filter" => Comments, ...))


80         array(

81             'class'=>'CButtonColumn',

82             'updateButtonOptions'=> array('style' => 'display:none'),

83         ),

84     ),

85 )); 

86 echo CHtml::endForm();

87 ?>


#12 	

+

 /var/www/html/framework/web/CBaseController.php(126): require("/var/www/html/cms_hort/protected/modules/admin/views/comments/in...")

#13 	

+

 /var/www/html/framework/web/CBaseController.php(95): CBaseController->renderInternal("/var/www/html/cms_hort/protected/modules/admin/views/comments/in...", array("model" => Comments), true)

#14 	

+

 /var/www/html/framework/web/CController.php(869): CBaseController->renderFile("/var/www/html/cms_hort/protected/modules/admin/views/comments/in...", array("model" => Comments), true)

#15 	

+

 /var/www/html/framework/web/CController.php(782): CController->renderPartial("index", array("model" => Comments), true)

#16 	

–

 /var/www/html/cms_hort/protected/modules/admin/controllers/CommentsController.php(139): CController->render("index", array("model" => Comments))


134         }

135         $model=new Comments('search');

136         $model->unsetAttributes();  // clear any default values

137         if(isset($_GET['Comments']))$model->attributes=$_GET['Comments'];

138 

139         $this->render('index',array('model'=>$model));

140     }

141 

142     /**

143      * Returns the data model based on the primary key given in the GET variable.

144      * If the data model is not found, an HTTP exception will be raised.


#17 	

+

 /var/www/html/framework/web/actions/CInlineAction.php(49): CommentsController->actionIndex()

#18 	

+

 /var/www/html/framework/web/CController.php(308): CInlineAction->runWithParams(array())

#19 	

+

 /var/www/html/framework/web/filters/CFilterChain.php(133): CController->runAction(CInlineAction)

#20 	

+

 /var/www/html/framework/web/filters/CFilter.php(40): CFilterChain->run()

#21 	

+

 /var/www/html/framework/web/CController.php(1145): CFilter->filter(CFilterChain)

#22 	

+

 /var/www/html/framework/web/filters/CInlineFilter.php(58): CController->filterAccessControl(CFilterChain)

#23 	

+

 /var/www/html/framework/web/filters/CFilterChain.php(130): CInlineFilter->filter(CFilterChain)

#24 	

+

 /var/www/html/framework/web/CController.php(291): CFilterChain->run()

#25 	

+

 /var/www/html/framework/web/CController.php(265): CController->runActionWithFilters(CInlineAction, array("accessControl", "postOnly + delete"))

#26 	

+

 /var/www/html/framework/web/CWebApplication.php(282): CController->run("")

#27 	

+

 /var/www/html/framework/web/CWebApplication.php(141): CWebApplication->runController("admin/comments")

#28 	

+

 /var/www/html/framework/base/CApplication.php(180): CWebApplication->processRequest()

#29 	

–

 /var/www/html/cms_hort/index.php(13): CApplication->run()


08 defined('YII_DEBUG') or define('YII_DEBUG',true);

09 // specify how many levels of call stack should be shown in each log message

10 defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);

11 

12 require_once($yii);

13 Yii::createWebApplication($config)->run();



Вот связь в модельке




	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(

            //связываем поле user с моделью User  и его полем user_id

            'user' => array(self::BELONGS_TO, 'User', 'user_id'),

            'page' => array(self::BELONGS_TO, 'Page', 'page_id'),

		);

	}

На OpenServer все работало…

Причем если заменить

        'value' =&gt; '&#036;data-&gt;user-&gt;username',

на

        //'value' =&gt; '&#036;data-&gt;page-&gt;title',

все нормально отрабатывает…

Прошу помощи!

Выведите $data->user:




'value'=>function($data){

    var_dump($data->user);

}



Скорее всего станет видно в чем проблема:

  • Ошибка в relation

  • Нет связанной записи

Спасибо за подсказку - попробовал.

Вот вывод одной из позиций

если я не ошибаюсь - username здесь присутствует…

вы правильно написали что "Вот вывод одной из позиций"

я подозреваю что в одной из позиций у вас просто NULL выводится так как там просто что то не то со связью

а так как вы пытаетесь обратится к NULL как к объекту и приводит к ошибке

для того чтоб отследить напишите так




'value'=>function($data){

if($data->user == null){

return 'Not Found';

}


return $data->user->username;

}



Вы оказались правы!!!

Спасибо, огромное, за неоценимую помощь !!

Вопрос решен