我正在尝试根据我的数据库中的值从不同的包中动态加载 yml 路由文件。我已经按照说明书创建了一个自定义路由加载器,但是在导入文件时出现错误。我正在开发 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”包已正确注册并加载到应用程序内核类中。在 C:\Program Files\wamp\www\alimerp\vendor\symfony\symfony\src\Symfony\Component\Config\Loader\Loader.php 第 77 行
为什么我会收到此错误?