Symfony2: No route found for “GET /lucky/number”

后端 未结 11 1116
北荒
北荒 2021-02-18 14:17

I start the tutorial (as newbie) and everythings works fine till:

http://symfony.com/doc/current/book/page_creation.html#creating-a-page-route-and-controller at step

相关标签:
11条回答
  • 2021-02-18 14:51

    Try this URL:

    http://[Server-IP]:8000/app_dev.php/en/lucky/number

    There's a bug in the Symfony Book: they forgot the demo app support i18n.

    Just add the "/en" parameter before the routing ones.


    I know this question it's closed but I hope my answer can help others that are still facing this problem.

    0 讨论(0)
  • 2021-02-18 14:56

    In case someone else runs into this problem: for me the problem was twofold:

    1. i forgot to assign a namespace namespace AppBundle\Controller;
    2. i didn't add a use statement for the template use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
    0 讨论(0)
  • 2021-02-18 15:02

    http://localhost:8080/SymfonyProject/web/app_dev.php/lucky/number

    It works for me. Change "SymfonyProject" with your project name folder or delete it if your project is pointed directly by the Server. Also pay attention to the port that works for you (localhost:8080). In my case is 8080, in your could be 8000 or something else.

    0 讨论(0)
  • 2021-02-18 15:04

    I copied and pasted your controller in an existing Symfony project and the route immediately appeared. So nothing wrong with the controller.

    I also compared the routing.yml and it's the same.

    The only thing that's left is to check the folder structure and make sure you don't have different Symfony projects mixed together; maybe you're editing the right file but starting the web server from a different path.

    Check carefully or rebuild the project in a completely different path. Since you're testing with the embedded web server, you don't need to put your project into /var/www/html (in fact it's better not to).

    0 讨论(0)
  • 2021-02-18 15:08

    Sometimes is a cache problem. Try to remove dev folder from /project/var/cache/dev.

    As authentictech says, also you can try the command:

    php bin/console cache:clear

    If you want to specify the environment, you should add the --env=prod property.

    0 讨论(0)
  • 2021-02-18 15:10

    I have just added a

    <?php
    

    to the file "LuckyNumberController" and it works.... really strange.

    Thanks everybody

    0 讨论(0)
提交回复
热议问题