9
votes

When following Symfony2's validation documentation (http://symfony.com/doc/current/book/validation.html) the writer often refers to

src/Acme/BlogBundle/Resources/config/validation.yml

I also have this file, at the proper location (accounting for my bundle name and vendor ofcourse) but it is completely ignored.

Do I need to load this from somewhere?

2

2 Answers

28
votes

You don't have to load the validation.yml programmaticaly. You just modify the config.yml to enable validation and to disable annotations:

framework:
    validation:      { enabled: true, enable_annotations: false }
6
votes

You need to load this in your Extension file src/Acme/BlogBundle/DependencyInjection/AcmeBlogExtension.php.

public function load(array $configs, ContainerBuilder $container)
{
    //...
    $yamlMappingFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
    $yamlMappingFiles[] = __DIR__.'/../Resources/config/validation.yml';
    $container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $yamlMappingFiles);
}