R
R
Rodion Yurchenko2017-03-03 22:56:02
symfony
Rodion Yurchenko, 2017-03-03 22:56:02

How to create Choice in Entity in symfony 3?

Good
afternoon I'm torturing Symfony, but she's me
The essence of the problem: you need to create a form with a choice (select) of 2 options
Question: is it possible to specify all valid 2 options in Entity ?
Before that, I worked with Django - and there selection options could be made right when declaring a field ...
Something tells me that in symphony you can do the same ...
Now in Entity like this:

use Symfony\Component\Validator\Constraints as Assert;


    /**
     * @var int
     *
     * @Assert\Choice( choices = {1:"male", 2:"female"}, message = "Choose a valid priority.")
     */
    protected $priority;

- but with doctrine:schema:update --force - no field appears in the database, and as I understand it, it shouldn't, since there is no field name anywhere ...
Tell me how to make a normal, beautiful choice

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Denis, 2017-03-04
@prototype_denis

The Assert annotation refers to the validation component. It has nothing to do with the doctrine and work with the base.
See the enum annotation for doctrine. symfony has great documentation. I'd deploy the symfony-demo for reference and a basic understanding.

V
Vadim, 2017-03-04
@kylt_lichnosti

Choice should be created in the form, not in essence.
"@Assert" refers to form validation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question