如何在symfony2表单中使用生日字段 [英] How to use birthday field in symfony2 forms

查看:216
本文介绍了如何在symfony2表单中使用生日字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Symfony Docs 说我们可以使用生日日期形式。但是他们没有给出任何例子如何使用

Symfony Docs say that we can use birthday date in forms. but they have not given any example how to use that

任何人都可以告诉我需要在哪里写 birthday in doctrine entity?

Can anyone please tell me where do I need to write birthday in doctrine entity?

推荐答案

生日是form_widget。

The Birthday is the form_widget.

恩。在控制器中:

$form = $this->createFormBuilder($task)
        ->add('task', 'text')
        ->add('yearOfBirth', 'birthday')
        ->getForm();

此小部件可以映射到DateTime字段

This widget can be mapped to DateTime field

/**
 * @var date $yearOfBirth
 *
 * @ORM\Column(name="year_of_birth", type="datetime")
 * @Assert\DateTime()
 */
private $yearOfBirth;

在此您可以参考有关此字段的文档:
http://symfony.com/doc/current/reference/forms/types/birthday.html

Here you got reference to docs about this field: http://symfony.com/doc/current/reference/forms/types/birthday.html

问候,
最高

这篇关于如何在symfony2表单中使用生日字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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