【发布时间】:2013-06-16 17:27:53
【问题描述】:
当我尝试访问我的 app_dev.php 页面时遇到以下错误:
No route found for "GET /"
问题是我定义了这条路由,我的 routing.yml 文件如下所示:
0 v42homepage:
1 pattern: /
2 defaults: { _controller: v42Bundle:Default:index }
3
4 v42meetTheTeamPage:
5 pattern: /meetTheTeam
6 defaults: { _controller: v42Bundle:Default:meetTheTeam }
7
8 v42whatWeDoPage:
9 pattern: /whatWeDo
10 defaults: { _controller: v42Bundle:Default:whatWeDo }
11
12 v42contactUsPage:
13 pattern: /contactUs
14 defaults: { _controller: v42Bundle:Default:contactUs }
15
16 v42homepage:
17 pattern: /login
18 defaults: { _controller: v42Bundle:Default:login }
这是我的控制器:
<?php
47
46 namespace v42\WebsiteBundle\Controller;
45
44 use Symfony\Bundle\FrameworkBundle\Controller\Controller;
43
42 class DefaultController extends Controller
41 {
40 public function indexAction()
39 {
38 $templating = $this->container->get('templating');
37
36 $response = $templating->renderResponse('v42Bundle:Default:index.html.twig');
35
34 return $response;
33 }
32
31 public function meetTheTeamAction()
30 {
29 $templating = $this->container->get('templating');
28
27 $response = $templating->renderResponse('v42Bundle:Default:meetTheTeam.html.twig');
26
25 return $response;
24 }
23
22 public function whatWeDoAction()
21 {
20 $templating = $this->container->get('templating');
19
18 $response = $templating->renderResponse('v42Bundle:Default:whatWeDo.html.twig');
17
16 return $response;
15 }
14
13 public function contactUsAction()
12 {
11 $templating = $this->container->get('templating');
10
9 $response = $templating->renderResponse('v42Bundle:Default:contactUs.html.twig');
8
7 return $response;
6 }
5
4 public function loginAction()
3 {
2 $templating = $this->container->get('templating');
1
0 $response = $templating->renderResponse('v42Bundle:Default:login.html.twig');
1
2 return $response;
3 }
4
5 }
我的所有其他路径都可以工作,但在不提供路径的情况下访问 app_dev.php 则不行,即使默认情况下这应该解析为我的 / 路径。这是什么原因造成的?
我已尝试使用 Symfony 的控制台程序清除缓存,如 here 所述。
谢谢
【问题讨论】:
-
快速提示 .. 使用 @Template 来精简你的控制器 -> symfony.com/doc/current/bundles/SensioFrameworkExtraBundle/…
-
@nifr 谢谢,我会检查一下,我对此非常陌生,这是我在 Symfony2 中的第一次郊游哈哈!
-
只需使用
$this->render()(或@nifr 建议的注释)