可能重复:
In Symfony2, can the validation.yml file be split into multiple files using imports?
在yml文件中添加验证约束之前是否需要执行任何操作。 我很难在doc上找到有关如何加载validation.yml文件的信息:
# src/Acme/BlogBundle/Resources/config/validation.yml
Acme\BlogBundle\Entity\Author:
properties:
firstName:
- NotBlank: ~
- MinLength: 3
从验证文件加载验证约束的步骤是什么?
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$ymlValidationFile = $container ->getParameter('validator.mapping.loader.yaml_files_loader.mapping_files');
$ymlValidationFile[] = __DIR__.'/../Resources/config/validation.yml';
$container->setParameter('validator.mapping.loader.yaml_files_loader.mapping_files',$ymlValidationFile);
}