0

嗨,我正在从 2.7 迁移到 symfony4。我确实有几个捆绑包,我按照说明操作:https ://symfony.com/doc/current/routing/external_resources.html

我的配置/bundle.php:

...
App\Frontend\MainBundle\FrontendMainBundle::class => ['all' => true],
...

我的配置/routes.yaml:

frontend_main:
    resource: "@AppFrontendMainBundle/Resources/config/routing.frontend.main.yml"
               #also tried here without App

我收到一条消息:

“frontend_main”下无法识别的选项“resource”。

我做错了什么?

4

1 回答 1

2

在具有 Flex 目录结构的 Symfony 4 中,调用默认路由文件config/routes.yaml,而不是routing.yaml. 您确定该文件是作为路由的一部分而不是作为服务配置加载的吗?

你应该检查你的路由配置内核在src/Kernel.php. 默认情况下,它看起来像这样:

protected function configureRoutes(RouteCollectionBuilder $routes)
{
    $confDir = $this->getProjectDir().'/config';
    if (is_dir($confDir.'/routes/')) {
        $routes->import($confDir.'/routes/*'.self::CONFIG_EXTS, '/', 'glob');
    }
    if (is_dir($confDir.'/routes/'.$this->environment)) {
        $routes->import($confDir.'/routes/'.$this->environment.'/**/*'.self::CONFIG_EXTS, '/', 'glob');
    }
    $routes->import($confDir.'/routes'.self::CONFIG_EXTS, '/', 'glob');
}

如果你想保留你的文件名,你可以重命名最后一个导入(或添加另一个):

$routes->import($confDir.'/routing'.self::CONFIG_EXTS, '/', 'glob');
于 2017-12-27T09:45:28.333 回答