Trying To Get Property Of Non-Object Error

hi all

I have a yii site which is part of a larger set of sites I am transferring to a new webhost for a client. Unfortunately I am very ignorant of yii :blink:

As a first step I have copied the site to my laptop. Generally it seems to be working fine but when I’m in a list / table page which displays data from the db, it throws an error when I click on Next for the following page. Error details are below. I have checked and this error does not happen on the live site. Presumably something different about the environment on my laptop but any idea where I might start to look?

Many thanks for any help :)


Error 500: <h1>PHP Error [8]</h1>

<p>Trying to get property of non-object (/var/www/cfh/yii/framework/base/CComponent.php(607) : eval()'d code:1)</p>

<pre>#0 /var/www/cfh/yii/framework/base/CComponent.php(607) : eval()'d code(1): CWebApplication->handleError()

#1 /var/www/cfh/yii/framework/base/CComponent.php(607): eval()

#2 /var/www/cfh/yii/framework/zii/widgets/grid/CDataColumn.php(139): CDataColumn->evaluateExpression()

#3 /var/www/cfh/yii/framework/zii/widgets/grid/CGridColumn.php(138): CDataColumn->renderDataCellContent()

#4 /var/www/cfh/yii/framework/zii/widgets/grid/CGridView.php(517): CDataColumn->renderDataCell()

#5 /var/www/cfh/yii/framework/zii/widgets/grid/CGridView.php(490): BootGridView->renderTableRow()

#6 /var/www/cfh/yii/framework/zii/widgets/grid/CGridView.php(400): BootGridView->renderTableBody()

#7 /var/www/cfh/yii/framework/zii/widgets/CBaseListView.php(158): BootGridView->renderItems()

#8 unknown(0): BootGridView->renderSection()

#9 /var/www/cfh/yii/framework/zii/widgets/CBaseListView.php(141): preg_replace_callback()

#10 /var/www/cfh/yii/framework/zii/widgets/CBaseListView.php(126): BootGridView->renderContent()

#11 /var/www/cfh/yii/framework/web/CBaseController.php(174): BootGridView->run()

#12 /var/www/cfh/protected/views/survey/index.php(23): SurveyController->widget()

#13 /var/www/cfh/yii/framework/web/CBaseController.php(127): require()

#14 /var/www/cfh/yii/framework/web/CBaseController.php(96): SurveyController->renderInternal()

#15 /var/www/cfh/yii/framework/web/CController.php(870): SurveyController->renderFile()

#16 /var/www/cfh/yii/framework/web/CController.php(783): SurveyController->renderPartial()

#17 /var/www/cfh/protected/controllers/SurveyController.php(250): SurveyController->render()

#18 /var/www/cfh/yii/framework/web/actions/CInlineAction.php(50): SurveyController->actionIndexAll()

#19 /var/www/cfh/yii/framework/web/CController.php(309): CInlineAction->runWithParams()

#20 /var/www/cfh/yii/framework/web/filters/CFilterChain.php(134): SurveyController->runAction()

#21 /var/www/cfh/yii/framework/web/filters/CFilter.php(41): CFilterChain->run()

#22 /var/www/cfh/yii/framework/web/CController.php(1146): CAccessControlFilter->filter()

#23 /var/www/cfh/yii/framework/web/filters/CInlineFilter.php(59): SurveyController->filterAccessControl()

#24 /var/www/cfh/yii/framework/web/filters/CFilterChain.php(131): CInlineFilter->filter()

#25 /var/www/cfh/yii/framework/web/CController.php(292): CFilterChain->run()

#26 /var/www/cfh/yii/framework/web/CController.php(266): SurveyController->runActionWithFilters()

#27 /var/www/cfh/yii/framework/web/CWebApplication.php(276): SurveyController->run()

#28 /var/www/cfh/yii/framework/web/CWebApplication.php(135): CWebApplication->runController()

#29 /var/www/cfh/yii/framework/base/CApplication.php(162): CWebApplication->processRequest()

#30 /var/www/cfh/index.php(13): CWebApplication->run()

</pre>

What do you have in this file:

[color=#222222][font=arial, sans-serif][size=3]/var/www/cfh/protected/views/[/size][/font][/color][color=#222222][font=arial, sans-serif][size=3]survey/index.php(23) ?[/size][/font][/color]

[color=#222222][font=arial, sans-serif][size=3]

[/size][/font][/color]

[font=“arial, sans-serif”][color="#222222"][size=3]Looks like you have a call to a variable that doesn’t contain an expected object in one of CGridView.[/size][/color][/font]

[font=“arial, sans-serif”][color="#222222"][size=3]Most probably, you’ll just need to add a check an object is set.[/size][/color][/font]

[font="arial, sans-serif"][color="#222222"][size=3]

[/size][/color][/font]

[font="arial, sans-serif"][color="#222222"][size=3]For example, this often happens when you call an empty relation model(s), e.g.[/size][/color][/font]

[font="arial, sans-serif"][color="#222222"][size=3]


$myModel->relationModel->relationData;

[/size][/color][/font]

[font="arial, sans-serif"][color="#222222"][size=3]

[/size][/color][/font]

[font="arial, sans-serif"][color="#222222"][size=3]And one question - do you have full production db data at your local installation?[/size][/color][/font]

hi Yugene, many thanks for your reply. The local version is using production data, and /var/www/cfh/protected/views/survey/index.php has this:


<?php

$this->menu=array(

	array('label'=>'Create Survey', 'url'=>array('create')),

);

?>


<h1>Surveys</h1>

<?php $this->widget('bootstrap.widgets.BootGridView', array(

	'dataProvider'=>$dataProvider,

	'template'=>'{items}{pager}',

	'itemsCssClass'=>'table table-striped table-condensed',

	/*'filter'=>$model,*/

	'columns'=>array(

		array('class'=>'CLinkColumn', 'header'=>'Household No.', 'labelExpression'=>'$data->household_number', 'urlExpression'=>'Yii::app()->createUrl("survey/view", array("id"=>$data->id))'),

		'date::Survey date',

		array('class'=>'CDataColumn', 'header'=>'Surveyor', 'value'=>'$data->user->first_name." ".$data->user->last_name', 'visible'=>Yii::app()->user->role=='admin'),

		array('class'=>'CDataColumn', 'header'=>'Householder', 'value'=>'$data->householder_last_name'),

		array('class'=>'CDataColumn', 'header'=>'Street name', 'value'=>'$data->street'),

		'postcode',

		array('class'=>'CLinkColumn', 'header'=>'Report', 'labelExpression'=>'"View report"', 'urlExpression'=>'Yii::app()->createUrl("survey/report", array("id"=>$data->id))'),

		array('class'=>'CButtonColumn', 'visible'=>Yii::app()->user->role=='admin'),

	),

)); ?>

I tried an alternate route to solving this which was to implement it in a staging environment on our web server instead of locally, and it works fine there. Bit cluncky for debugging but good enough for my purposes :)

Thanks again

Andy