Hi there,
Since I’ve never been using eval() function (still having Rasmus Lerdorf, creator of PHP - If eval() is the answer, you’re almost certainly asking the wrong question - words in my mind, see last (bottom of page) post on that page :]), I have some problems understanding how it works.
I’m trying to change CDataColumn.value, which uses eval. I’m trying to format date that I’m receiving in this column, therefore I call:
$this->widget('zii.widgets.grid.CGridView', array
(
...
'columns'=>array
(
'ID',
array
(
'name'=>'DATR',
'value'=>'date("Y-m-d H:i:s", $data->DATR)',
),
'STAT',
'BCODE',
...
),
));
This works perfectly, because I’m receiving PHP timestamp in this column, which can be formatted with only one line. Problems starts when I change DB query and receive formal date or if anything forces me to use more than one PHP code line in value (eval) call. An example of object approach to use PHP’s DateTime::format uses two lines of code:
<?php
$date = new DateTime('2000-01-01');
echo $date->format('Y-m-d H:i:s');
?>
I tried to use it in value on a various ways:
'value'=>'$date = new DateTime("2000-01-01");echo $date->format("Y-m-d H:i:s");',
or
'value'=>'$date = new DateTime("2000-01-01");return $date->format("Y-m-d H:i:s");',
or
'value'=>'new DateTime("2000-01-01")->format("Y-m-d H:i:s")',
Always with no luck - various errors from either PHP parser, Yii exception catcher or parse error inside GridView’s cell.
Therefore, I’m asking what is the correct format for using more than one line of code in eval function?