Yii formatting date and filters

点点圈 提交于 2019-12-24 21:22:05

问题


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 formatting the output data in yii?


回答1:


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



来源:https://stackoverflow.com/questions/11891629/yii-formatting-date-and-filters

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!