I am trying to implement something similar to the way Yii CActiveDataProvider parse complex expressions. Take the following codes as an example, I would basically like to be able to specify something like ‘date(“M j, Y”, $data->create_time)’ in the value.
Any one knows which class in Yii will provide good insight? I looked at CDataColumn class, but not much luck.
$this-widget('zii.widgets.grid.CGridView', array(
'dataProvider'=$dataProvider,
'columns'=array(
'title', // display the 'title' attribute
'category.name', // display the 'name' attribute of the 'category' relation
'content:html', // display the 'content' attribute as purified HTML
array( // display 'create_time' using an expression
'name'='create_time',
'value'='date("M j, Y", $data-create_time)',
),
),
));
Do you want to create a widget that can evaluate a PHP Expression?
There is this method
evaluateExpressionwhich is also used by CDataColumn. You can see how the CDataColumn use it in the methodrenderDataCellContent.As you see the code inside method
evaluateExpression, it is usingevalandcall_user_func.And if you use PHP 5.3, you can use anonymous function for this. e.g.