是否有可能从config?
中的子目录导入services.yml文件我有这样的结构:
[Acme/MyBundle/Resources]
--[config]
----[routing]
----[services]
------[User]
--------services.yml
----[validation]
----routing.yml
----services.yml
----validation.yml
现在我想将文件Acme/MyBundle/Resources/config/services/User/services.yml
导入Acme/MyBundle/Resources/config/services.yml
,DependencyInjection/AcmeMyExtension
加载Acme/MyBundle/Resources/config/services.yml
。 imports:
- { resource: "@AcmeMyBundle/Resources/config/services/User/services.yml" }
services:
//other services
中的代码是:
Fatal error: Uncaught exception 'InvalidArgumentException' with message 'The file "@AcmeMyBundle/Resources/config/services/User/services.yml" does not exist (in: ., C:\wamp\www\dir\src\Acme\MyBundle\DependencyInjection/../Resources/config).' in C:\wamp\www\dir\app\cache\dev\classes.php:1518
Stack trace: #0 C:\wamp\www\dir\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php(70): Symfony\Component\Config\FileLocator->locate('@AcmeMyBundle/...', '.', false) #1 C:\wamp\www\dir\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php(97): Symfony\Component\Config\Loader\FileLoader->import('@AcmeMyBundle/...', NULL, false, 'services.yml') #2 C:\wamp\www\dir\vendor\symfony\symfony\src\Symfony\Component\DependencyInjection\Loader\YamlFileLoader.php(54): Symfony\Component\DependencyInjection\Loader\YamlFileLoader->parseImports(Array, 'services.yml') #3 C:\wamp\www\dir\src\Acme\MyBundle\DependencyInjection\AcmeMyExtension.php(26): Symfony\Co in C:\wamp\www\dir\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\FileLoader.php on line 100
我收到错误:
<?php
namespace Core\MpgBundle\DependencyInjection;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
/**
* This is the class that loads and manages your bundle configuration
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
class CoreMpgExtension extends Extension
{
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
{
$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
}
}
Acme / MyBundle / DependencyInjection / AcmeMyExtension.php的代码:
{{1}}
答案 0 :(得分:1)
我能够通过以下方式实现这一目标:
在.htaccess
/^([A-F | N-Z]\d._-]{1,6})$/
现在,为什么会出现这种情况,而不是典型的/^[^G-M]/
?我怀疑是因为DependencyInjection类还没有完成处理,框架无法使用该注释来确定事物所在的位置。那些对内部人员更有见识的人可以证实。
答案 1 :(得分:0)
即使您要导入的文件位于子文件夹中,也可以在yml文件中导入其他资源。
例如,接受您有一个名为config.yml
的文件,并且您想在名为assets
的子文件夹下导入其他yml文件,您可以导入您的不同的yml文件,如下所示:
#config.yml file
imports:
- { resource: assets/design.yml }
- { resource: assets/params.yml }
您还可以导入整个目录以加载其中的所有资源:
#config.yml file
imports:
- { resource: assets/ }
例如,请参阅symfony doc here
希望这可以帮到你。