StErMi
(Stermi)
1
I’m going to take the doc example, with my version.
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array( // display 'create_time' using an expression
'name' => 'title',
'htmlOptions'=>array('style'=>'color:#'.$currentRowOfdataProvider->priority->priorityLabel.';'),
),
'desc',
array( // display 'create_time' using an expression
'name' => 'end',
'value' => date($user->config->dateFormat, $currentRowOfdataProvider->end),
),
'end',
'priority.priorityLabel',
'privacy',
'url',
'location',
'address',
array(
'class'=>'CButtonColumn',
),
),
));
Every row of $dataProvider has en element ‘end’ that specify the end date of an event, and other attribute. how can i use them?
StErMi
(Stermi)
2
Up! I see that I can use the expression ‘$data->fieldName’ on the value.
But when you add text, it will print nothing in that column:
example:
This works well
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array( // display 'create_time' using an expression
'type' => 'raw',
'name' => 'title',
'value' => '$data->title',
),
array(
'class'=>'CButtonColumn',
),
),
));
but when you change like this it doesnt work, the title field will be printed empty:
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider'=>$dataProvider,
'columns'=>array(
array( // display 'create_time' using an expression
'type' => 'raw',
'name' => 'title',
'value' => 'Something before $data->title something after',
),
array(
'class'=>'CButtonColumn',
),
),
));
StErMi
(Stermi)
3
solved:
you need to define a function like:
<?php
function echoMe ( $data ) {
return 'bla bla bla' . $data;
}
?>
and then you can use
array( // display 'create_time' using an expression
'name' => 'fieldName',
'value' => 'echoMe( $data->fielName )',
),