我正在尝试根据我的数据库中的值动态加载来自不同包的yml路由文件。我跟着cookbook创建了一个自定义路由加载器,但导入文件时出错了。我正在研究Symfony 2.3。当我在 routing.yml 文件中手动添加集合时,我的路由工作正常。
我已经创建了一项加载资源的服务:
class ExtraLoader implements LoaderInterface
{
private $loaded = false;
public function load($resource, $type = null)
{
if (true === $this->loaded) {
throw new \RuntimeException('Do not add the "extra" loader twice');
}
$loader = new AdvancedLoader($this->getResolver());
$routes = new RouteCollection();
$route = $loader->import('@ERPExsecBBundle/Resources/config/routing.yml');
$route->addPrefix('/Production/');
$routes->addCollection($route);
$this->loaded = true;
return $routes;
}
[...]
}
如食谱中所述的高级装载机:
class AdvancedLoader extends Loader
{
public function __construct($resolver) {
$this->resolver = $resolver;
}
public function load($resource, $type = null)
{
$collection = new RouteCollection();
$type = 'yaml';
$importedRoutes = $this->import($resource, $type);
$collection->addCollection($importedRoutes);
return $importedRoutes;
}
public function supports($resource, $type = null)
{
return $type === 'advanced_extra';
}
}
但是我收到了一个错误:
致命错误:未捕获异常'Symfony \ Component \ Config \ Exception \ FileLoaderLoadException',消息'无法加载资源'@ ERPExsecBBundle / Resources / config / routing.yml“。确保在应用程序内核类中正确注册并加载“ERPExsecBBundle / Resources / config / routing.yml”包。在第77行的C:\ Program Files \ wamp \ www \ alimerp \ vendor \ symfony \ symfony \ src \ Symfony \ Component \ Config \ Loader \ Loader.php
为什么我收到此错误?
答案 0 :(得分:2)
在食谱中他们说:
# app/config/routing.yml
AcmeDemoBundle_Extra:
resource: .
type: extra
其中"键入"应该与AdvancedLoader的类型相匹配
public function supports($resource, $type = null)
{
return $type === 'advanced_extra';
}
您应该尝试替换"额外" by" advanced_extra"在您的app / config / routing.yml
中答案 1 :(得分:-1)
您是否在AppKernel.php中注册了捆绑包ERPExsecBBundle?