I am making use of CGridview widget with the ‘columns’ property being ‘CLinkColumn’, because I would like to embed a link to the other table (view).What I would like to do is the following.
'columns'=>array(
:
array(
'class'=>'CLinkColumn',
'labelExpression'=>'$data->code', // this line is fine!
'url'=>array(
'member/admin',
'code'=>'$data->code', // this line is NG!
),
:
It is not working because ‘url’ parameter does not recognize ‘$data’ keyword, though I would like to link this item to ‘actionAdmin’ of ‘MemberController’ having dynamic ‘code’ parameter.I actually did following but failed because urlExpression does not recognize array structure on the other hand.
'columns'=>array(
:
array(
'class'=>'CLinkColumn',
'labelExpression'=>'$data->code', // this line is fine!
'urlExpression'=>array( // this line is NG!
'member/admin',
'code'=>'$data->code',
),
:
array( 'class'=>'CLinkColumn',
'header'=>'Last Name',
'labelExpression'=>'$data->ParticipantLastname',
'urlExpression'=>'Yii::app()->createUrl("participant/list",array("lastname"=>$data->ParticipantLastname))',
'linkHtmlOptions'=>array('title'=>'See all entries with this last name'))
I was using CArrayDataProvider instead of CActiveDataProvider so I couldn’t use object notation to reference the data I wanted. I struggled trying to get the syntax correct.
In case it helps someone else, here’s the change. Instead of
'labelExpression'=>'$data->ParticipantLastname',
you change it to array referencing AND escape the quotes:
BTW - it also took me a while to understand that $row and $data are magically available. $row is the current row number, $data is an array of the data for that row.