In Symfony2, can the validation.yml file be split into multiple files using imports?
Add these lines in load
method of src/Blogger/BlogBundle/DependencyInjection/BloggerBlogExtension.php
.
public function load(array $configs, ContainerBuilder $container)
{
//...
$yamlMappingFiles = $container->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$yamlMappingFiles[] = __DIR__.'/../Resources/config/comment.yml';
$yamlMappingFiles[] = __DIR__.'/../Resources/config/enquiry.yml';
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files', $yamlMappingFiles);
}
Answer added at 2015
As of Symfony
2.7
, XML and Yaml constraint files located in theResources/config/validation
sub-directory of a bundle are loaded.
Prior to2.7
, onlyResources/config/validation.yml
(or .xml) were loaded.
More info at:
- Github PR: [FrameworkBundle] "mappings" for validation #13878
- Symfony doc: The Basics of Validation
Symfony 2.5 broke the above solutions. See: https://stackoverflow.com/a/24210501/175753