url/urlExpression property of the CLinkColumn

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',

                ),

          :



Is there any good way to do it?

// I have found an ugly WA though…

Does this help?


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'))

doodle

Thanks doodle,

That works fine!

I can’t seem to get the ‘linkHtmlOptions’ to register. I’m using the latest version of Yii with the following code;


 array( 'class'=>'CLinkColumn',

                        'header'=>'Print',

                        'labelExpression'=>'"Print Order #$data->products_orders_id"',

                        'urlExpression'=>'Yii::app()->createUrl("productsOrders/print",array("id"=>$data->products_orders_id))',

                        'linkHtmlOptions'=>array('target'=>'_blank')),  

Everything works except the ‘linkHtmlOptions’ which seem to be getting ignored… Any ideas?

Try this…





'linkHtmlOptions'=>array('target'=>'"_blank"'),




+1 me if it helps! :rolleyes:

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:




'labelExpression'=>'$data[\'ParticipantLastname\']',



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.

HTH someone.

I know this is an old thread, but just wanted to add yet another way of adding a url with params…

This fixes the error: "Undefined variable: data" in CLinkColumn.


	

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

'columns'=>array(	

array(

      'class'=>'CLinkColumn',

      'labelExpression'=>'$data->name',

      'urlExpression'=>'array("controller/action", "id"=>$data->id)',

    ),

...

)

...

));