Yii 格式化日期和过滤器

编程入门 行业动态 更新时间:2024-10-10 15:22:05
本文介绍了Yii 格式化日期和过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我有一个日期字段,需要显示为日/月/年并保存为年-月-日.我想为此使用 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/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/samdark/a-guide-to-yii-grids-lists-and-data-providers/blob/master/grid-columns.md

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

更多推荐

[db:关键词]

本文发布于:2023-04-23 18:28:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1047459.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:过滤器   日期   Yii

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!