In Symfony2, can the validation.yml file be split into multiple files using imports?(在 Symfony2 中,validation.yml 文件可以使用导入拆分成多个文件吗?)
问题描述
现在,我有一个名为 validation.yml 的文件,其中在一个文件中验证了捆绑包的所有实体.
Right now, I have a file called validation.yml with the validation of all the bundle's entities in one file.
validation.yml
validation.yml
BloggerBlogBundleEntityComment
properties:
username:
- NotBlank:
message: You must enter your name
- MaxLength: 50
comment:
- NotBlank:
message: You must enter a comment
- MinLength: 50
BloggerBlogBundleEntityEnquiry:
properties:
name:
- NotBlank: ~
email:
- Email:
message: symblog does not like invalid emails. Give me a real one!
subject:
- NotBlank: ~
- MaxLength: 50
body:
- MinLength: 50
但我想将其拆分为两个文件并将它们都导入.这是我尝试过的,但没有成功:
But I'd like to split it into two files and import them both. This is what I tried and it didn't work:
validation.yml
validation.yml
imports:
- { resource: comment.yml }
- { resource: enquiry.yml }
comment.yml
comment.yml
BloggerBlogBundleEntityComment
properties:
username:
- NotBlank:
message: You must enter your name
- MaxLength: 50
comment:
- NotBlank:
message: You must enter a comment
- MinLength: 50
enquiry.yml
enquiry.yml
BloggerBlogBundleEntityEnquiry:
properties:
name:
- NotBlank: ~
email:
- Email:
message: symblog does not like invalid emails. Give me a real one!
subject:
- NotBlank: ~
- MaxLength: 50
body:
- MinLength: 50
推荐答案
在 src/Blogger/BlogBundle/DependencyInjection/BloggerBlogExtension.php 的 load 方法中添加这些行.
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);
}
这篇关于在 Symfony2 中,validation.yml 文件可以使用导入拆分成多个文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Symfony2 中,validation.yml 文件可以使用导入拆分成多个文件吗?
基础教程推荐
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01
