问题
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