phpyiicdetailview

display date in cdetailsview in Yii


I have the code below in view.php of a model:

<?php $this->widget('zii.widgets.CDetailView', array(
'data'=>$model,
'attributes'=>array(
    'id',
    'name',
    'cat_id',
    'price',
            array(
                'name' => 'create_date',
                'header' => 'Create Date',
                'value' => 'Yii::app()->dateFormatter->format("yyyy-MM-dd HH:mm:ss", $data->create_date)'
            ),
    array(
                'name' => 'update_date',
                'header' => 'update Date',
                'value' => 'Yii::app()->dateFormatter->format("yyyy-MM-dd HH:mm:ss", $data->update_date)'
            ),
            array(
                'name' => 'last_visit_date',
                'header' => 'Last visit Date',
                'value' => 'Yii::app()->dateFormatter->format("yyyy-MM-dd HH:mm:ss", $data->last_visit_date)'
            ),
    'hit',
    'update_count',
    'status',
    'sold',
    'active',
),

)); ?>

but I see

Yii::app()->dateFormatter->format("yyyy-MM-dd HH:mm:ss", $data->last_visit_date)

instead of converted date. I use this in admin.php and it is ok but in view.php it is not.


Solution

  • Delete quotes, use this:

    'value' => Yii::app()->dateFormatter->format("yyyy-MM-dd HH:mm:ss", $model->last_visit_date)