ggogggo
(Ggogggo)
October 20, 2010, 2:50pm
1
hi there
i have a problem with setting the template property of CButtonColumn
i smth like this
$this->widget(‘zii.widgets.grid.CGridView’, array(
...
'deactivated_at',
array(
'class'=>'CButtonColumn',
'template'=>empty($data->deactivated_at) ? '{update} | {delete}':' {update} ',
…
as i saw it in an example in this forum, but i get
PHP Error
Description
Undefined variable: data
i tried it also like this: ( put the condition in single quotes)
$this->widget(‘zii.widgets.grid.CGridView’, array(
...
'deactivated_at',
array(
'class'=>'CButtonColumn',
'template'=>'($data->deactivated_at)' ? '{update} | {delete}':' {update} ',
…
but then it always shows me {update} | {delete}, i guess it doesn’t parse the ($data->deactivated_at), but just seet it’s not empty
how should i do this?
thanks
g3ck0
(S H A R K)
October 20, 2010, 2:58pm
2
There is a visible -property for each button (look here). There you can set a PHP expression which should do the job.
mikl
(Mike)
October 20, 2010, 3:01pm
3
You can’t use an expression for the template property. Instead use the buttons property and define the expression for visible :
'buttons'=>array(
'delete'=>array(
'visible'=>'$data->deactivated_at',
),
),
iivano71
(Igor Zg1987)
October 20, 2010, 4:18pm
4
You have sintax error in your logic you cant use
‘template’=>empty($data->deactivated_at) ? ‘{update} | {delete}’:’ {update} ',
try
‘template’=>empty($data->deactivated_at) ? ‘{delete}’:’{update}’,
this should solve your issue
mikl
(Mike)
October 21, 2010, 7:05am
5
You have sintax error in your logic you cant use
‘template’=>empty($data->deactivated_at) ? ‘{update} | {delete}’:’ {update} ',
try
‘template’=>empty($data->deactivated_at) ? ‘{delete}’:’{update}’,
this should solve your issue
It will not, as this expression is only evaluated once, when the data grid is initialized. ggogggo needs an expression that is evaluated for every row (as you can see from his use of the $data object).
Please avoid to post so much source code as this clutters the forum. It’s better to link to the API docs (where you can also expand the source code) or even to the SVN code browser at google code.
iivano71
(Igor Zg1987)
October 21, 2010, 8:48am
7
It will not, as this expression is only evaluated once, when the data grid is initialized. ggogggo needs an expression that is evaluated for every row (as you can see from his use of the $data object).
Please avoid to post so much source code as this clutters the forum. It’s better to link to the API docs (where you can also expand the source code) or even to the SVN code browser at google code.
ok thanks, i will post link next time, i apologize for wrong answer
You can’t use an expression for the template property. Instead use the buttons property and define the expression for visible :
'buttons'=>array(
'delete'=>array(
'visible'=>'$data->deactivated_at',
),
),
Thanks very much, man, that’s exactly what I was looking for
thanks,
this is what work for me…
'approve' => array(
'label'=>'Approve',
'imageUrl'=>Yii::app()->request->baseUrl.'/images/email.png',
'options'=>array('style'=>'padding:0 5px 0 0;'),
'url'=>'Yii::app()->controller->createUrl("statusapprove",array("id"=>$data->primaryKey))',
'visible'=>'($data->requestStatus=="new" || $data->requestStatus=="deny" )?true:false',
),