2

I have read about new feature: symfony 4.3 Automatic validation https://symfony.com/blog/new-in-symfony-4-3-automatic-validation So Doctrine annotation should suffice without explicitly manually adding Validator annotations ( like @Assert\NotNull() ..) Yet I do not understand how to make it work. I have symfony 4.3 application, currently create Entities, really do not want to add Validator annotations manually but use this new Automatic validation feature. I am newby to Symfony, please be detailed.

//$post is Entity with title notNull property
$errors = $validator->validate($post);

/**
     * @var string
     *
     * @Assert\NotNull()
     * @ORM\Column(name="title", type="string", length=10, nullable=false)
     */

It should work without explicitly adding @Assert\NotNull() but it doesn't

Mikhail Zhuikov
  • 1,213
  • 2
  • 9
  • 19
avrahamm
  • 79
  • 6

1 Answers1

3

https://symfonycasts.com/screencast/symfony-forms/assert-validation

The answer is in https://symfonycasts.com/screencast/symfony-forms/assert-validation see Conversation. Briefly config/packages/validator.yaml like:

framework: validation: email_validation_mode: html5

    # Enables validator auto-mapping support.
    # For instance, basic validation constraints will be inferred from Doctrine's metadata.

HERE! uncomment 2 line below and Automatic validation should work

    auto_mapping:
        App\Entity\: []
avrahamm
  • 79
  • 6