skapeyi
(Kapeyisamson)
March 13, 2014, 11:59am
1
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.
<?php
$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(
'dataProvider'=>$provide,
'columns'=>array(
'id',
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.
1cichy
(Czaty)
March 13, 2014, 12:23pm
2
Try use CLinkColumn or:
'value' => 'CHtml::link($data->surname, Yii::app()->createUrl(\'staff/view\',array(\'id\'=>$data->id)))'
skapeyi
(Kapeyisamson)
March 13, 2014, 1:21pm
3
The escape characters haven’t worked. Let me look into CLinkColumn then i will get back to you.
Thanks though.
skapeyi
(Kapeyisamson)
March 13, 2014, 1:48pm
4
I have tried to use CLinkColumn, and it hasn’t helped either.
array(
'class'=>'CLinkColumn',
'labelExpression'=>'$data->surname',
'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.
AlexInt
(Alex)
March 13, 2014, 2:54pm
5
Try this:
'column1' => array(
'name' => 'column1',
'type' => 'raw',
'value'=>'CHtml::link($data->column1, array("controllerID/view", "id"=>$data->id))',
),
skapeyi
(Kapeyisamson)
March 13, 2014, 3:31pm
6
AlexInt:
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 "
Thanks
konapaz
(Konapaz)
March 13, 2014, 4:16pm
7
skapeyi:
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.
<?php
$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(
'dataProvider'=>$provide,
'columns'=>array(
'id',
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.
Hi
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
skapeyi
(Kapeyisamson)
March 14, 2014, 5:42am
8
KonApaz:
Hi
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…
Thank you Very Much…
For those of you who may have a similar problem here is the code that worked.
'columns'=>array(
'surname' => array(
'name' => 'surname',
'type' => 'raw',
'value'=>'CHtml::link($data["surname"], array("Staff/view", "id"=>$data["id"]))',
),
),
konapaz
(Konapaz)
March 18, 2014, 4:28pm
9
skapeyi:
Oh My God, It worked…
Thank you Very Much…
For those of you who may have a similar problem here is the code that worked.
'columns'=>array(
'surname' => array(
'name' => 'surname',
'type' => 'raw',
'value'=>'CHtml::link($data["surname"], array("Staff/view", "id"=>$data["id"]))',
),
),
Also check this
http://www.yiiframework.com/wiki/639/csqldataprovider-in-cgridview
skapeyi
(Kapeyisamson)
March 25, 2014, 11:21am
10
Thanks I will make use of this someday. Added it to bookmarks.
deviasi
(Deviasier)
May 22, 2014, 1:03am
11
Thank u so much bro, you helping me this problem make me stuck for 3 days programming.
God Bless You