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 working. 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.

//$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

1 Answer 1

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\: []
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.