PcPhpDataColumn
General
While developing a table using CGridView, I needed to run a code snippet for each row (and for each data object being handled/rendered in that row). I couldn't use CDataColumn since the PHP code CDataColumn expect is simple and would need to be run when prefixed by 'return...'. The PcPhpDataColumn class provided by this extension is an 'extension' (OO term) of CDataColumn and overwrites its evaluateExpression() method to allow running of more complex code snippets. Note: if you wish, you can also achieve running more complex code using anonymous functions (in PHP v5.3+) or some custom model methods, instead of using this extension.
$this->widget('zii.widgets.grid.CGridView', array( 'id' => 'my-id', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array( // other columns... array( 'class' => 'PcPhpDataColumn', 'name' => 'table_column_name', 'header' => 'Column header text', 'value' => '$a = Yii::app()->someComp->someCalc($data); $b = new SomeClass($a); return $b->getSomeData();', ), ), ));
Be the first person to leave a comment
Please login to leave your comment.