Problem With Cgridview And Anonymous Function

I have the following code:

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







                    'value'=>'function(){ print "op" }',






)); ?>

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:


Any ideas on what I am doing wrong here?






if you want to display value from function, Create one function in current model and call using below code





Thanks. I already knew how to call a method from the model. But in the manual it says:

I would like to see how to call an anonymous function as I am using php > 5.3 :)

Dear Friend

If you put the value in single quotes, CComponent::evaluateExpression will evaluate the expresssion.

If you pass without quotes, it will call the anonymous function.

The anonymous function should have proper signature.



		'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.


thanks seenivasan.