php - 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 文件中而不是包含外部资源 - 一切正常。
解决方案
Symfony 有严格的 Bundle 类命名规则,我在文档中找到了这些规则: https ://symfony.com/doc/current/bundles/best_practices.html
因此,我的 Bundle 类现在从App\ICatcher\Builder\Builder
to重命名,App\ICatcher\Builder\ICatcherBuilder
并且文件以相同的方式重命名ICatcherBuilder.php
并且可以正常工作。
推荐阅读
- javascript - React:只切换一个类而不影响现有类
- python - python django中的名称未定义错误
- javascript - 类属性必须是方法。预期 '(' 但看到 '='
- css - 列表不会随变换移动
- azure-devops - 在 VSTS 中,连接到 dockerized ArangoDB 数据库的异步 Jest 测试超时
- python - 在 numpy 中广播数组
- firebase - FCM 显示消息有时很慢
- curl - Paypal PDT Curl 没有响应
- php - Laravel 5.6 是否存在将一些自定义变量传递给 Http Resource 集合的方式?
- html - 即使 H1 和它的容器都有更大的宽度(HTML/CSS),H1 也不会使用所有可用空间