9

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?

peterrus
  • 651
  • 2
  • 6
  • 18

2 Answers2

28

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 }
Alberto Gaona
  • 2,427
  • 25
  • 20
  • This is the correct way, assuming you follow convention and create the Resources/config/validation.yml file within your bundle (Symfony 2.3). The key is that you have to disable annotations, which are enabled by default. – Andrew Sep 19 '13 at 23:43
  • 2
    what if i want to use both? im using annotation everywhere but i need to overwrite FOS_User validation. validation.xml works but validation.yml doesnt – gondo Jan 29 '14 at 20:30
  • Did you try with app/Resources/FOSUserBundle/config/validation.xml? – Alberto Gaona Jan 29 '14 at 23:47
  • 3
    We use `validation: { enable_annotations: true }` (no mention of `enabled: true`) and can (and do) use both: validation.yml and annotations (Symfony 2.3.8). – flu Oct 09 '14 at 09:44
6

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);
}
Carlos Granados
  • 11,273
  • 1
  • 38
  • 44
  • 5
    Thanks! Where did you find this information? as I had the same problem with adding security and routing files without doing dirty includes in my global app/config – peterrus Sep 11 '12 at 13:29
  • peterrus, please consider don't consider this the best answer, but the one of @alberto-goana. – Nuno Pereira Jan 18 '16 at 18:22