bettor
(Live Webscore)
January 29, 2013, 1:16pm
1
I have the following code:
<?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'post-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
array(
'name'=>'title',
'value'=>'function(){ print "op" }',
),
array(
'class'=>'CButtonColumn',
),
),
)); ?>
The result is "op" is printed on the top of the page instead of in the proper cell. Am I using something wrong. It becomes even worse if I am using a static method such as:
'value'=>'Post::render',
Any ideas on what I am doing wrong here?
cheers!
mmbalaa
(Mmbalasundaram)
January 29, 2013, 1:25pm
2
array(
'name'=>'title',
'value'=>'op',
),
if you want to display value from function, Create one function in current model and call using below code
array(
'name'=>'title',
'value'=>'$data->functionname($data->title)',
),
bettor
(Live Webscore)
January 29, 2013, 1:38pm
3
array(
'name'=>'title',
'value'=>'op',
),
if you want to display value from function, Create one function in current model and call using below code
array(
'name'=>'title',
'value'=>'$data->functionname($data->title)',
),
Thanks. I already knew how to call a method from the model. But in the manual it says:
http://www.yiiframework.com/doc/api/1.1/CComponent#evaluateExpression-detail
I would like to see how to call an anonymous function as I am using php > 5.3
seenivasan
(Chellamnivas)
January 29, 2013, 1:53pm
4
Dear Friend
If you put the value in single quotes, CComponent::evaluateExpression will eval uate the expresssion.
If you pass without quotes, it will call the anonymous function.
The anonymous function should have proper signature.
array(
'header'=>"Test",
'value'=>function($data,$row,$object) {
echo $data->title;
echo $row;
echo $object->id;
},
),
The parameters should be in the in the same order mentioned.
$data represents the data object representing current row.
$row is 0 based index numbering rows.
$object is the component itself,here it is instance of CDataColumn.
The same way class methods and methods of object can be passed.
Regards.