yiisoft/yii

Use of undefined constant id / CGridView widget

tonykor opened this issue · 2 comments

Use of undefined constant id - assumed 'id' (this will throw an Error in a
future version of PHP) (/app/yii/framework/base/CComponent.php(614) :
eval()'d code:1)
Stack trace:
#0 /app/yii/framework/base/CComponent.php(614): eval()
#1 /app/yii/framework/zii/widgets/grid/CButtonColumn.php(360):
CButtonColumn->evaluateExpression()
#2 /app/yii/framework/zii/widgets/grid/CButtonColumn.php(339):
CButtonColumn->renderButton()
#3 /app/yii/framework/zii/widgets/grid/CGridColumn.php(237):
CButtonColumn->getDataCellContent()
#4 /app/yii/framework/zii/widgets/grid/CGridColumn.php(160):
CButtonColumn->renderDataCellContent()
#5 /app/yii/framework/zii/widgets/grid/CGridView.php(655):
CButtonColumn->renderDataCell()
#6 /app/yii/framework/zii/widgets/grid/CGridView.php(639):
CGridView->renderDataCell()
#7 /app/yii/framework/zii/widgets/grid/CGridView.php(595):
CGridView->renderTableRow()
#8 /app/yii/framework/zii/widgets/grid/CGridView.php(505):
CGridView->renderTableBody()
#9 /app/yii/framework/zii/widgets/CBaseListView.php(181):
CGridView->renderItems()
#10 unknown(0): CGridView->renderSection()
#11 /app/yii/framework/zii/widgets/CBaseListView.php(164):
preg_replace_callback()
#12 /app/yii/framework/zii/widgets/CBaseListView.php(149):
CGridView->renderContent()
#13 /app/yii/framework/web/CBaseController.php(182): CGridView->run()

Changing yii/framework/base/CComponent.php(614) to

return @eval('return ' . $_expression_ . ';');

fixes the problem

Additional info

Q A
Yii version 1.1.26
PHP version 7.4.27

@tonykor Your issue information is incomplete: the stack trace does not include the custom $expression that is parsed here, and that one most likely contains the problem. Can you provide a complete example?

Hi @marcovtwout the problem was due to this array in colums of CGridView widget

                 array(
			'class'=>'CButtonColumn',
			'template'=>'{update}{delete}',
			'deleteButtonOptions'=>array('class'=>'deleteButton'),
			'deleteButtonImageUrl'=>$this->themeBaseUrl."/gfx/delete.gif",
			'updateButtonImageUrl'=>$this->themeBaseUrl."/gfx/edit.gif",
			'updateButtonOptions'=>array('style'=>'margin: 0 15px;'),
			'updateButtonUrl'=>'CHtml::normalizeUrl(array("users/edit", id=>$data->id))',
			'viewButtonImageUrl'=>$this->themeBaseUrl."/gfx/view.gif",
		),

I have changed

'updateButtonUrl'=>'CHtml::normalizeUrl(array("users/edit", id=>$data->id))',

to

'updateButtonUrl'=>'CHtml::normalizeUrl(array("users/edit", "id"=>$data->id))',

it was my error sorry.