Reputation: 329
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 AcmeDemoBundle and I'm trying to run an example bundle from a symfony2 tutorial. What is wrong ?
app/config/routing.yml :
ShopMyShopBundle:
resource: "@ShopMyShopBundle/Resources/config/routing.yml"
prefix: /
app/config/routing_dev.yml :
_assetic:
resource: .
type: assetic
_wdt:
resource: "@WebProfilerBundle/Resources/config/routing/wdt.xml"
prefix: /_wdt
_profiler:
resource: "@WebProfilerBundle/Resources/config/routing/profiler.xml"
prefix: /_profiler
_configurator:
resource: "@SensioDistributionBundle/Resources/config/routing/webconfigurator.xml"
prefix: /_configurator
_main:
resource: routing.yml
src/Shop/MyShopBundle/Resources/config/routing.yml :
ShopMyShopBundle_homepage:
pattern: /hello/{name}
defaults: { _controller: ShopMyShopBundle:Main:index }
requirements:
_method: GET
Upvotes: 22
Views: 119143
Reputation: 23381
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');
}
Upvotes: 1
Reputation:
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
Upvotes: 12
Reputation: 81
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
Upvotes: 3
Reputation: 1139
I have also tried that error , I got it right by just adding /hello/any name because it is path that there must be an hello/name
example : instead of just putting http://localhost/app_dev.php
put it like this way http://localhost/name_of_your_project/web/app_dev.php/hello/ai
it will display Hello Ai . I hope I answer your question.
Upvotes: 0
Reputation: 15087
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 }
Upvotes: 1
Reputation: 44831
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
Upvotes: 21