Question

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.

Was it helpful?

Solution

Delete quotes, use this:

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

OTHER TIPS

You need to delete the quotes, because the CDetailView can only show one record. I think you also need to change $data to $model like this:

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

If you want to show multiple records, you can use CListView

Note:

In the CDetailView you're using a CModel as data and in the CListView you're using a dataProvider

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top