Problem With Cgridview And Anonymous Function

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!


    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 :)

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.




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.

thanks seenivasan.