Symfony4捆绑包的外部路由
嗨,我正在从2.7迁移到symfony4。我确实有几个包,我按照说明操作: My config/bundle.php:Symfony4捆绑包的外部路由,symfony,symfony4,Symfony,Symfony4,嗨,我正在从2.7迁移到symfony4。我确实有几个包,我按照说明操作: My config/bundle.php: ... App\Frontend\MainBundle\FrontendMainBundle::class => ['all' => true], ... 我的配置/routes.yaml: frontend_main: resource: "@AppFrontendMainBundle/Resources/config/routing.frontend.
...
App\Frontend\MainBundle\FrontendMainBundle::class => ['all' => true],
...
我的配置/routes.yaml:
frontend_main:
resource: "@AppFrontendMainBundle/Resources/config/routing.frontend.main.yml"
#also tried here without App
我得到一个信息:
“前端_main”下未识别的选项“资源”
我做错了什么?在具有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');
在具有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');
是的,它是默认值。对不起,只是拼写错误。当然是yaml。symfony4的绝对默认值。是的,它是默认值。对不起,只是拼写错误。当然是yaml。symfony4的绝对默认值。我粘贴了您的资源代码,得到了一条捆绑包不存在的消息。这并不奇怪,因为我没有包裹。无法识别的错误更像是格式/缩进错误。config/routing.yaml中还有其他内容吗?我粘贴了您的资源代码,得到了一条捆绑包不存在的消息。这并不奇怪,因为我没有包裹。无法识别的错误更像是格式/缩进错误。config/routing.yaml中还有其他内容吗?