我有一个 symfony 项目。 我正在尝试添加一个新页面,并且我已经执行了常规步骤,但似乎没有任何效果。 我已将以下内容添加到 src/ITWB/FrontBundle/Resources/config/routing.yml:
itwb_front_abc:
pattern: /abcCenter
defaults: { _controller: ITWBFrontBundle:Footer:abcCenter }
在我的 src/ITWB/FrontBundle/Controller/FooterController.php 中我添加了以下内容:
public function abcCenterAction() {
return $this->render('ITWBFrontBundle::test.html.twig');
}
但它不起作用。 我尝试将“echo”放入操作中,但它没有显示,因此,问题出在路由中,domain.com/abcCenter 未被识别。我也尝试过其他名字,都是一样的。
我能做什么? 谢谢
您忘记了选项的缩进。缩进是 Yaml 的一个非常重要的方面:
itwb_front_abc:
pattern: /abcCenter
defaults: { _controller: ITWBFrontBundle:Footer:abcCenter }
注意缩进,就像 Wouter J 所说。
如果您的网站在本地运行,您可以通过domain.com/app_dev.php/abcCenter(不是domain.com/abcCenter)访问abcCenter,否则您必须清除缓存:
php app/console cache:clear --env=prod --no-debug
我要查看的第一个地方:在 app/config/routing.yml 中,您是否引用了捆绑包的routing.yml?
app/config/routing.yml 文件应包含几行,如下所示:
front_bundle:
resource: "@FrontBundle/Resources/config/routing.yml"
当然,也许您已经完成了此操作,作为您提到的“常规步骤”的一部分?
我在 Symfony 5.4 应用程序中面临同样的问题。这个命令帮助了我:
php bin/console cache:clear --env=prod --no-debug