Yii formating date and filters

2019-08-29 11:24发布

I have an date field that need to be presented as day/month/year and saved as year-month-date. I thought in using CFilter for that but since it apply a function after the action it would be executed before the renderization.

Should i put it on an event, is there a default approach for filtering input data and formating the output data in yii?

标签: php yii
1条回答
可以哭但决不认输i
2楼-- · 2019-08-29 11:35

The easiest way to do it is to pass your information to a CGridView / CDetailView as a type of date:

'columns'=>array(
    array(
        'name'=>'checkout',
        'type'=>'date',
    ),
),

Passing in a type then formats it with the corresponding formatDate function CFormatter. It's incredibly handy / flexible. That way you don't even have to convert your dates to a different format. More info here: https://github.com/samdark/a-guide-to-yii-grids-lists-and-data-providers/blob/master/grid-columns.md

查看更多
登录 后发表回答