Answer the question
In order to leave comments, you need to log in
If you use a form component, where is it better to specify constraints?
There is a variant of the task of constraints, validation rules in the entity itself, or when creating a form.
/**
* @var string
*
* @ORM\Column(type="string", length=255)
*
* @Assert\NotBlank()
* @Assert\Type(
* type="string",
* )
*/
private $firstName;
или
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('firstName', TextType::class, [
'required' => true,
constraints' => array(new NotBlank()....))
])
Answer the question
In order to leave comments, you need to log in
I chose the first option using annotations. If you choose the second one, the buildForm function can turn into an analogue of "code noodles". The second minus of the second approach is arrays within arrays.
In general, as I understand it, it's a matter of taste.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question