Mirage
Mirage

Reputation: 31558

How to use birthday field in symfony2 forms

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?

Upvotes: 0

Views: 4126

Answers (2)

Max Małecki
Max Małecki

Reputation: 1702

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

Upvotes: 2

j0k
j0k

Reputation: 22756

$builder->add('dateOfBirth', 'birthday');

You have plenties of example on the internet:

Upvotes: 1

Related Questions