Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2 how to load validation.yml

Tags:

symfony

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?

like image 357
peterrus Avatar asked Sep 11 '12 10:09

peterrus


2 Answers

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 }
like image 197
Alberto Gaona Avatar answered Nov 06 '22 21:11

Alberto Gaona


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);
}
like image 22
Carlos Granados Avatar answered Nov 06 '22 22:11

Carlos Granados