Cgridview With Column As A Link

Dear all,

So i have a query i am running, and when it returns the data, i want to make one column linkable to view the whole node.

So i run the query like this.


	$command = Yii::app()->db->createCommand();

	$staff = $command->select('*')->from('staff')->queryAll();

	$provide= new CArrayDataProvider($staff, array(


	)); ?>

Then i display the returned data with CGridView like this.

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





			'name'  => 'surname',

        	'value' => 'CHtml::link($data->surname, Yii::app()->createUrl("staff/view",array("id"=>$data->id)))',

        	'type'  => 'raw',		





)); ?>

I want the surname to be a link to the whole node which shows all the information of the staff member.However, I get an error, somewhere. See details in the images attached.

Any help to fix this will be highly appreciated.

Try use CLinkColumn or:

'value' => 'CHtml::link($data->surname, Yii::app()->createUrl(\'staff/view\',array(\'id\'=>$data->id)))'

The escape characters haven’t worked. Let me look into CLinkColumn then i will get back to you.

Thanks though.

I have tried to use CLinkColumn, and it hasn’t helped either.




					'urlExpression'=>'Yii::app()->createUrl("staff/view", array("id"=>$data->id))',



From the error, I am starting to think it has something to do with the data that it is actually retrieving to make the links. I still haven’t figured out what it is exactly.

Try this:

'column1' => array(

            'name' => 'column1',

            'type' => 'raw',

            'value'=>'CHtml::link($data->column1, array("controllerID/view", "id"=>$data->id))',


Just did, gave me the same notice, "Trying to get property of non-object "



queryAll of CDbCommand returns array (each row) of array (attributes) so

‘value’=>‘CHtml::link($data->column1, array(“controllerID/view”, “id”=>$data->id))’,

$data->column1 and $data->id should becomes from object (your model) but $data in your case is an array

So, test your code using $data["id"] and $data["column1"]

Please inform us if it works :)

Oh My God, It worked… ;D

Thank you Very Much…

For those of you who may have a similar problem here is the code that worked.


					'surname' => array(

            'name' => 'surname',

            'type' => 'raw',

            'value'=>'CHtml::link($data["surname"], array("Staff/view", "id"=>$data["id"]))',



Also check this

Thanks I will make use of this someday. Added it to bookmarks.

Thank u so much bro, you helping me this problem make me stuck for 3 days programming.

God Bless You