willbelair
(Willbelair)
November 5, 2013, 8:50pm
1
Hello,
yii version is yii-1.1.14
I know this is very simple and posted many places, but I can’t get it done. I have tried anything to get it displayed but the $model->CallNumber just return null.
array(
'header'=>'Call #',
'name'=>'CallNumber',
'value'=>"CHtml::link('$model->CallNumber)','test')",
'type'=>'raw',
),
Please help
bettor
(Live Webscore)
November 5, 2013, 9:27pm
2
how about this
'value'=>"CHtml::link($data->CallNumber),'test')",
p.s. I would assume the above is CGridView
willbelair
(Willbelair)
November 5, 2013, 9:32pm
3
bettor:
how about this
'value'=>"CHtml::link($data->CallNumber),'test')",
p.s. I would assume the above is CGridView
Thank you for your reply. It is in gridview. And looks like you have a typo, missing an open ( . But it still show in null.
‘value’=>“CHtml::link(($data->CallNumber),‘test’)”,
andy_s
(Arekandrei)
November 6, 2013, 5:24am
4
Should be:
'value'=>"CHtml::link($data->CallNumber, 'url')",
and make sure $data->CallNumber is not empty.
Ankit_Modi
(Ankit Modi)
November 6, 2013, 5:28am
5
andy_s:
Should be:
'value'=>"CHtml::link($data->CallNumber, 'url')",
and make sure $data->CallNumber is not empty.
try this for e.g
'value'=>'CHtml::link($data["available_artist"] ? \'active\': \'inactive\' ,"javascript:void(0);",array("class"=>"status11","onclick"=>"aritstsetchanges({$data["id"]})"))' ,
also simple
array(
'name'=>'url',
'value'=>'CHtml::link($data->url, $data->url, array(\'target\' => \'_blank\'))',
'type'=>'raw',
),
I hope it’s some help
daredevil
(Chirag Iiit)
November 6, 2013, 10:47am
6
willbelair:
Hello,
yii version is yii-1.1.14
I know this is very simple and posted many places, but I can’t get it done. I have tried anything to get it displayed but the $model->CallNumber just return null.
array(
'header'=>'Call #',
'name'=>'CallNumber',
'value'=>"CHtml::link('$model->CallNumber)','test')",
'type'=>'raw',
),
Please help
Try this
array(
'header'=>'Call #',
'value'=>'(($model->CallNumber!='')?(CHtml::link($model->CallNumber,"url-link"))<img src='http://www.yiiframework.com/forum/public/style_emoticons/default/sad.gif' class='bbc_emoticon' alt=':(' />"Not available"))',
'type=>'raw',
)
willbelair
(Willbelair)
November 6, 2013, 3:37pm
7
Thank you all for your help, but none working. If there is no syntax error, then the $model->CallNumber return null, even though the same $model->CallNumber used in different column shows data. That is what really bugging me. I tried \ escape the $ ,but still no result. Any thoughts please.
andy_s
(Arekandrei)
November 6, 2013, 4:46pm
8
It should be $data->CallNumber, not $model->CallNumber. Does it work with other fields, like $data->id?
willbelair
(Willbelair)
November 6, 2013, 5:23pm
9
Yes it does. ($model or $data not mater here, in my code it is $model, but the others helped me used $data)
if doing this:
array(
'header'=>'Call #',
'name'=>'CallNumber',
'value'=>$model->CallNumber,
)
the value will show in column. But if adding “CHtml::link(’$model->number’,’$myurl’)” it just show null.
If I change to use class ‘class’=>‘CLinkColumn’, and urlExpression , same thing happen. By the value of $model->CallNumber does not show.
Also, any field will be the same if used in this link creation.
andy_s
(Arekandrei)
November 6, 2013, 6:06pm
10
It DOES matter.
With this code:
'value'=>$model->CallNumber,
all grid rows will display the same value ($model->CallNumber)
With this code:
'value'=>'$data->CallNumber'
each row will contain a CallNumber of a corresponding model. I did a mistake in my first post. There should be single quotes, because this statement will be executed per each row later (using eval(), where a row model is represented by $data variable). Hope it helps
willbelair
(Willbelair)
November 6, 2013, 6:37pm
11
thanks Andy,
I just can’t get it going. Why $data->CallNumber show null? If put at another place it shows.
andy_s
(Arekandrei)
November 6, 2013, 7:44pm
12
What is another place? Can you post a complete code of that grid or whole view file?
willbelair
(Willbelair)
November 6, 2013, 8:39pm
13
thanks,
this is the controller:
public function actionAdmin()
{
$model=new Callinfo('search');
$model->unsetAttributes();
if(isset($_GET['Callinfo']))
$model->attributes=$_GET['Callinfo'];
$this->render('admin',array(
'model'=>$model
));
}
and this is the view:
<?php
/* @var $this CallinfoController */
/* @var $model Callinfo */
$this->breadcrumbs=array(
'Callinfos'=>array('index'),
'Manage',
);
$test = '123';
$myurl = 'thisistheone';
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'callinfo-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'header'=>'Call #',
'name'=>'CallNumber',
//'value'=>$model->CallNumber, // THIS WILL SHOW DATA
//'value' => "CHtml::link('$myurl','$test')",
'value' => "CHtml::link('$model->CallNumber','$test')", // THIS RETURN NULL
'type' => 'raw',
),
array(
'class'=>'CLinkColumn',
'label'=>'viewCall',
'urlExpression'=>"callinfo/view/id='$model->CallNumber",
'header'=>'Author'
),
array(
'header'=>'Status',
'name'=>'CallStatus',
'value'=>$model->CallStatus,
'filter'=>$model->callstatus()
),
),
)); ?>
andy_s
(Arekandrei)
November 7, 2013, 6:10am
14
http://www.yiiframework.com/doc/api/1.1/CDataColumn#value-detail
If you have PHP 5.3+, then I hope anon functions will help you faster to understand how grid work:
$this->widget('zii.widgets.grid.CGridView', array(
'id'=>'callinfo-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'header'=>'Call #',
'name'=>'CallNumber',
'value'=>function($data) { return CHtml::link($data->CallNumber, 'link'); },
'type' => 'raw',
),
array(
'class'=>'CLinkColumn',
'label'=>'viewCall',
'urlExpression'=>function($data) { return 'callinfo/view/id='.$data->CallNumber; },
'header'=>'Author'
),
array(
'header'=>'Status',
'name'=>'CallStatus',
'value'=>function($data) { return $data->CallStatus; },
'filter'=>$model->callstatus()
),
),
)); ?>
willbelair
(Willbelair)
November 7, 2013, 2:19pm
15
thank you Andy. That is the one that I was suspecting, the version of either php or yii, but not getting to the right documents. I was working with yii on and off (mostly off) for last 2 years, and did not get my knowledge updated.
Thanks again.