首页 > 解决方案 > Symfony 路由资源和 Bundle 名称

问题描述

我试图将一个文件包含到 Symfony 4 路由中,但无法弄清楚放入 Bundle 名称的正确方法是什么。我的路线.yml:

icatcher_builder:
    # loads routes from the given routing file stored in some bundle
    resource: '@ICatcher/Builder/Resources/config/routes.yaml'

我的 bundles.php:

App\ICatcher\Builder\Builder::class => ['dev' => true, 'test' => true],

我得到这个错误:

在渲染模板期间抛出异常(“Bundle“ICatcher”不存在或未启用。也许您忘记将其添加到 App\Kernel.php 文件的 registerBundles() 方法中?在@ICatcher 中) /Builder/Resources/config/routes.yaml(从“[PATH]\config/routes.yaml”导入)。确保“ICatcher/Builder/Resources/config/routes.yaml”包已正确注册并在应用程序内核类中加载。如果捆绑包已注册,请确保捆绑包路径“@ICatcher/Builder/Resources/config/routes.yaml”不为空。”)。

如果我只是将路由复制到主 route.yml 文件中而不是包含外部资源 - 一切正常。

标签: phpsymfonysymfony4

解决方案


Symfony 有严格的 Bundle 类命名规则,我在文档中找到了这些规则: https ://symfony.com/doc/current/bundles/best_practices.html

因此,我的 Bundle 类现在从App\ICatcher\Builder\Builderto重命名,App\ICatcher\Builder\ICatcherBuilder并且文件以相同的方式重命名ICatcherBuilder.php并且可以正常工作。


推荐阅读