简体   繁体   中英

Symfony 2: “No route found for ”GET /" - error on fresh installation

I am trying to begin my education of symfony 2 and started with it's tutorial. One of first things I tried was to install symfony 2 and configure it.

When I try to access http://127.0.0.1:8000/ , I am getting an incomplete site with the following error:

ERROR - Uncaught PHP Exception Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpException: "No route found for "GET /"" at /home/spectator/webprojects/cls/app/cache/dev/classes.php line 2059

Things I have tried so far:

  • clearing cache ( php app/console cache:clear --env=prod --no-debug )
  • recursively changing permissions to folder cls (symfony 2 folder) to 775 and even 777 (for diagnostics purposes)
  • adding "/" route to routing.yml and routing_dev.yml
  • reinstalling and
  • re-chmod symfony 2.

Try http://localhost:8000/app/example

Fresh installation has no routes for the root path "/"

first you need to set a default route edit the routing.yml app/config/routing.yml

app:
resource: @AppBundle/Controller/  # bundle name / Controller name
type:     annotation  # type of routing or 
# app/config/routing.yml   # file routing 


app: 
resource: @AppBundle/Controller/ 
prefix: / 

you can learn more in http://symfony.com/doc/current/book/routing.html

The default installation does not come with a default route for "/".

The example controller only defines a route of

@Route("/app/example", name="homepage")

In the past, a fresh Symfony installation also included some simple demo code to learn how does the framework work. A few months ago we decided to change this behavior by the following:

  1. A fresh Symfony installation no longer contains any demo code.
  2. A new "Symfony Demo Application" has been published for people learning the framework ( read more about this demo application).

If you use the Symfony Installer , you should do the following:

  1. When learning Symfony, execute the symfony demo command
  2. When creating a new Symfony project, execute the symfony new my_project command

I had the same problem. Just add <?php in the top of the file. Looks like if we don't specify it s

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM