why my symfony routing is not working?

24,026

First, you must be sure that routing.yml import the file routing_dev.yml.

Then, you must define the $name variable passed in argument in the route. If this argument is optional, you can give it a default value.

Moreover, note that you can put the prefix directly in the annotation.

/**
 * @Route("/blog")
 */
class TheClassController extends Controller
{
    /**
     * @Route("/{name}", name="_test", defaults={"name" = "Jean"})
     * @Template()
     */
    public function indexAction($name)
    {
         return array('name'=>$name);
    }
}

After, you can run run the command php app/console router:debug for test the route.

Share:
24,026

Related videos on Youtube

gurehbgui
Author by

gurehbgui

Nothing to say!

Updated on September 13, 2020

Comments

  • gurehbgui
    gurehbgui over 2 years

    hi i have a problem with my routing in symfony. my routing_dev looks like:

    _test:
        resource: "@MyBundle/Controller/DefaultController.php"
        type:     annotation
        prefix:   /test
    

    then i have a controller:

    /**
     * @Route("/", name="_test")
     * @Template()
     */
    public function indexAction($name)
    {
        return array('name' => $name);
    }
    

    and when i try to run the /test i get the message:

    No route found for "GET /test"
    404 Not Found - NotFoundHttpException
    1 linked Exception: ResourceNotFoundException »
    

    i dont know where the error is. i need your help. how to find the problem?

    EDIT: I'm working with the app_dev.php not app.php

    • Cyprian
      Cyprian about 10 years
      run this in your console: app/console router:debug - it might by very useful to determine what is wrong
  • Ziumin
    Ziumin about 10 years
    do u have the route with the same name (name="_test")?
  • gurehbgui
    gurehbgui about 10 years
    hmm, i did it, but there is no line with _test
  • gurehbgui
    gurehbgui about 10 years
    okay, this now added a /test when i call "php app/console router:debug" but still i get No route found for "GET /test"
  • gurehbgui
    gurehbgui about 10 years
    okay, this now added a @Route("/test", name="test") when i call "php app/console router:debug" but still i get No route found for "GET /test"
  • Flask
    Flask about 10 years
    I did not the updated answer.. especially the part about the routing yml.
  • Eskil Mjelva Saatvedt
    Eskil Mjelva Saatvedt almost 5 years
    for symfony 3.4: php bin/console debug:router

Related