在教义中坚持 Symfony DateIntervalType 并将其格式化为 twig [英] Persisting Symfony DateIntervalType in doctrine and format it in twig

查看:22
本文介绍了在教义中坚持 Symfony DateIntervalType 并将其格式化为 twig的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个问题与 DateIntervalType 相关Symfony 3.2 中引入的字段类型.此字段允许用户在表单中选择时间间隔.

This question is relative to The DateIntervalType field type introduced in Symfony 3.2. This field allows the user to select an interval of time in a form.

我想知道它对应的学说类型以及如何在树枝中格式化它,例如 2 小时 30 分钟?

I would like to know its corresponding doctrine type and how to format it in twig as for example 2 hours and 30 minutes ?

谢谢!

推荐答案

doctrine dbal(由doctrine orm使用)已经支持dateinterval.链接在这里:http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#dateinterval

The doctrine dbal (which is used by doctrine orm) supports dateinterval already. Here is the link: http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#dateinterval

用 twig 显示日期间隔非常简单,只需使用 date 过滤器,该过滤器在内部使用 DateInterval::format 方法.

Display a dateinterval with twig is really easy, just use the date filter which internally use the DateInterval::format method.

这篇关于在教义中坚持 Symfony DateIntervalType 并将其格式化为 twig的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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