【发布时间】:2018-03-13 05:47:32
【问题描述】:
Atm 我正在尝试迁移 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) 完美配合,但不能使用路由配置。
【问题讨论】:
-
您的路由需要在
app/config/routing.yml或添加的捆绑包中。 -
您是否使用了正确的 YamlFileLoader (
Symfony\Component\Routing\Loader\YamlFileLoader)?此外,您的$loader->load('master.yml')与您的routes.yml文件名不匹配。 -
routing.yml 已经在 config 文件夹中,我只是举了一个 master.yml 的例子来说明 YamlFileLoader 为另一个配置文件工作,但不适用于 routing.yml :) 更新代码以避免误解了。
-
您是否使用正确的 YamlFileLoader 读取它?服务一将只允许参数或服务,而路由一将允许路由。
-
@Qoop 请将此添加为anwser,我会标记它,你是对的,它们有相似的名称,而且我使用的是 DI 组件的 YamlFileLoader,而不是路由。