I am using Yii framework and I have a problem. I have created a widget in extension folder and trying to render my widget inside a CGridView. The partial code (my grid) is like that:
'columns'=>array(
'id',
'name',
array(
'type' => 'raw',
'value' => $this->widget('application.extensions.jalali.gregorian2jalali',array())
),
It gives me the following error while running:
Error 500
call_user_func_array() expects parameter 1 to be a valid callback, no array or string given
What is the problem coming from?
I was wondering the same and found out the following works for me:
Note that the example is based on widgets of the Yii Bootstrap extension.
Note the Yii::app()->controller->widget... wrapped in ".
When a column is specified as an array, it will be used to create a grid column instance, where the 'class' element specifies the column class name (defaults to CDataColumn if absent). Currently, these official column classes are provided: CDataColumn, CLinkColumn, CButtonColumn and CCheckBoxColumn.
http://www.yiiframework.com/doc/api/1.1/CGridView#columns-detail
and value in CDataColumn : a PHP expression that will be evaluated for every data cell using evaluateExpression and whose result will be rendered as the content of the data cell. In this expression, you can use the following variables: $row the row number (zero-based). $data the data model for the row. $this the column object. A PHP expression can be any PHP code that has a value. To learn more about what an expression is, please refer to the php manual.
just copy pasted it!
value is specified incorrectly, it needs to be a string like so:
Alternative render widget in GridView and CGridColumn Try to push the widget into a function like
e.g: in Post model (Post.php file), create a new function named
gregorian2jalali()
then in the view: