How to use birthday field in symfony2 forms

2019-08-28 09:00发布

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

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

2条回答
老娘就宠你
3楼-- · 2019-08-28 09:47

The Birthday is the form_widget.

ex. in controller:

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

This widget can be mapped to DateTime field

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

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

Regards, Max

查看更多
登录 后发表回答