我正在尝试迁移php代码
$routes->add(
'index',
new Route('/', ['_controller' => 'getIndex'])
);
到YML配置
index:
path: /
defaults: { _controller: 'getIndex' }
但是我收到了错误
'There is no extension able to load the configuration for "index" (in /app/config\routes.yml).
YamlFileLoade只是无法读取这种类型的配置,但为什么呢?我正在使用本指南http://symfony.com/doc/current/components/routing/introduction.html和我的代码来加载配置
$config = array(__DIR__ . '/app/config');
$loader = new YamlFileLoader($container, new FileLocator($config));
$loader->load('master.yml');
$collection = $loader->load('routing.yml');
已经与服务容器(master.yml)完美配合,但没有路由配置。
答案 0 :(得分:2)
首先,路由配置与DI配置不同。您现在正尝试使用DI配置机制加载路由。
要使用路线,您应该创建一个文件app/config/routing.yml
。这是路线生活的地方。如果要将路由放入捆绑包中,则无法使用DI扩展类来加载它们。您必须将它们包含在app/config/routing.yml
文件中,如下所示:
acme_demo_routes:
resource: @AcmeDemoBundle/Resources/config/routes.yml
答案 1 :(得分:1)
根据要求发布评论作为答案......
你使用正确的YamlFileLoader读取它吗?服务(DI)只允许参数或服务,而路由选择将允许路由。
路由=> Symfony\Component\Routing\Loader\YamlFileLoader
DI => Symfony\Component\DependencyInjection\Loader\YamlFileLoader