Yii 格式化日期和过滤器 [英] Yii formatting date and filters

查看:33
本文介绍了Yii 格式化日期和过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个日期字段,需要显示为日/月/年并保存为年-月-日.我想为此使用 CFilter,但由于它在操作之后应用了一个函数,因此它将在渲染之前执行.

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.

我应该把它放在一个事件上,在yii中是否有过滤输入数据和格式化输出数据的默认方法?

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

推荐答案

最简单的方法是将您的信息作为日期类型传递给 CGridView/CDetailView:

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',
    ),
),

传入一个类型,然后使用相应的 formatDate 函数 CFormatter 对其进行格式化.它非常方便/灵活.这样您甚至不必将日期转换为不同的格式.更多信息:https://github.com/samdark/a-guide-to-yii-grids-lists-and-data-providers/blob/master/grid-columns.md

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

这篇关于Yii 格式化日期和过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆