Zend Framework 2:在视图中格式化日期 [英] Zend Framework 2: formatting a date in a view
问题描述
我是Zend框架的新手,因此决定尝试使用ZF2构建一个简单的应用程序.
I'm new to Zend framework and have decided to try to build a simple app using ZF2.
我有一个要从数据库中提取日期的数据库,在该数据库中我的表网关扩展了AbstractTableGateway,这正确地提取了我的数据,但是我想使用Zend_Date格式化我的日期,而不是自己在模型中操纵字符串表示形式/看法.
I have a date that is being pulled from the database where my table gateway extends the AbstractTableGateway, this is pulling my data correctly but i'd like to format my date using Zend_Date and not manipulate the string representation myself in my model / view.
有人对我该怎么做有任何想法吗?
Does anybody have any ideas about how i do this?
推荐答案
以下是我自定义的数据时间帮助程序供参考:
Here is my custom datatime helper for reference:
https://github.com/AlloVince/eva -engine/blob/master/vendor/Eva/View/Helper/Datetime.php
将此帮助程序注册为模块配置文件中的可调用帮助程序服务
register this helper as a invokable helper service in your module config file
'view_helpers' => array(
'invokables' => array(
'datetime' => 'Eva\View\Helper\Datetime',
),
),
然后通过以下方式调用它:
Then call it in view by:
$this->datetime(time(), 0, 'Y-m-d'); //2012-10-09
$this->datetime()->jsTime(time()); //Sat Oct 6 17:16:05 UTC+0800 2012
这篇关于Zend Framework 2:在视图中格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!