symfony 2 No route found for “GET /”

后端 未结 7 1222
[愿得一人]
[愿得一人] 2020-12-17 09:54

Symfony2 returns No route found for \"GET /\" when I try to run http://localhost/app_dev.php, but this url works: http://localhost/app_dev.php/hello/Symfony. I removed AcmeD

相关标签:
7条回答
  • 2020-12-17 10:00

    This work for me:

    cache:clear --env=prod
    
    0 讨论(0)
  • 2020-12-17 10:05

    i could have been only one who made this mistake but maybe not so i'll post.

    the format for annotations in the comments before a route has to start with a slash and two asterisks. i was making the mistake of a slash and only one asterisk, which PHPStorm autocompleted.

    my route looked like this:

    /*
     * @Route("/",name="homepage")
     */
    public function indexAction(Request $request) {
        return $this->render('default/index.html.twig');
    }
    

    when it should have been this

    /**
     * @Route("/",name="homepage")
     */
    public function indexAction(Request $request) {
        return $this->render('default/base.html.twig');
    }
    
    0 讨论(0)
  • 2020-12-17 10:06

    The above answers are wrong, respectively aren't answering why you're having troubles viewing the demo-content prod-mode.

    Here's the correct answer: clear your "prod"-cache:

    php app/console cache:clear --env prod
    
    0 讨论(0)
  • 2020-12-17 10:23

    Using symfony 2.3 with php 5.5 and using the built in server with

    app/console server:run
    

    which should output something like:

    Server running on http://127.0.0.1:8000
    Quit the server with CONTROL-C.
    

    then go to http://127.0.0.1:8000/app_dev.php/app/example

    this should give you the default, which you can also find the default route by viewing src/AppBundle/Controller/DefaultController.php

    0 讨论(0)
  • 2020-12-17 10:25

    The problem is that you don't have a route for /. Change your definition to this:

    ShopMyShopBundle_homepage:
        pattern:  /
        defaults: { _controller: ShopMyShopBundle:Main:index }
        requirements:
            _method:  GET
    
    0 讨论(0)
  • 2020-12-17 10:25

    Prefix is the prefix for url routing. If it's equals to '/' it means it will have no prefix. Then you defined a route with pattern "it should start with /hello".

    To create a route for '/' you need to add these lines in your src/Shop/MyShopBundle/Resources/config/routing.yml :

    ShopMyShopBundle_homepage:
        pattern:  /
        defaults: { _controller: ShopMyShopBundle:Main:index }
    
    0 讨论(0)
提交回复
热议问题