Skip to content
Advertisement

No route found for /, even though a route is defined

I’m getting the following error when I try and visit my app_dev.php page:

No route found for "GET /"

The thing is that I defined this route, my routing.yml file looks like this:

 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 }

And here is my controller:

<?php
 47
 46 namespace v42WebsiteBundleController;
 45
 44 use SymfonyBundleFrameworkBundleControllerController;
 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 }

All of my other paths work, but visiting app_dev.php without providing a path does not, even though this should resolve to my / path by default. What could cause this?

I have tried clearing my cache with Symfony’s console program as described here.

Thanks

Advertisement

Answer

What was called pattern is now called path in the routing configuration. The old key pattern is deprecated and will be removed in Symfony 3.0.

Reference here.

If you use a different routing for the dev enviroment i.e. routing_dev.yml:

config_dev.yml

framework:
    router:   { resource: "%kernel.root_dir%/config/routing_dev.yml" }

You have to import the production routes in routing_dev.yml

routing_dev.yml

# ... dev routes here ... i.e. _wdt, _profiler

_main:
    resource: routing.yml

Furthermore make sure you dont overwrite the / route in routing_dev.yml.

the first matching route-pattern always wins – the routes before the import of routing.yml in routing_dev.yml will overwrite.

But … using the same route-names overwrites the ones declared earlier.

You can check which routes exist in your application with

app/console router:debug

app/console router:debug --env=prod

problem here: dublicate route names

v42homepage:
    pattern:  /

v42homepage:
    pattern:  /login

solution

rename the second v42homepage to i.e. v42login to resolve the issue.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement