Reputation: 109
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
Upvotes: 2
Views: 915
Reputation: 109
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.
auto_mapping:
App\Entity\: []
Upvotes: 3