Reputation:
When I use this configuration:
#/app/config/routing.yml
_org_demo:
resource: "@OrgDemoBundle/config/routing.yml"
#Org/DemoBundle/config/routing.yml
_home:
path: /{name}
defaults: { _controller: OrgDemoBundle:Home:index, name: world}
Both /
and /xyz
loads fine.
But, when I use the new configuration
#/app/config/routing.yml
_org_demo:
resource: "@OrgDemoBundle/config/routing.yml"
prefix: /hello
#Org/DemoBundle/config/routing.yml
_home:
path: /{name}
defaults: { _controller: OrgDemoBundle:Home:index, name: world}
In this case /hello/xyz
load but not /hello/
and I get error No route found for "GET /hello/"
. Why /hello/
not loads in this case and how can I fix this?
Upvotes: 0
Views: 400
Reputation: 3394
That's correct You can load /hello
though. It is not an error to fix.
Using hard coded URL is not a good practice. You should use generated URLs.
To generate URL from controller USE:
$this->generateUrl('_home'); //Will return /helo
$this->generateUrl('_home', array('name' => 'Bangladesh')) // will return /hello/Bangladesh
On twig template you can use these to have similar output :
{{ path('_home') }}
{{ path('_home', {name: 'Bangladesh' }) }}
If you like to handle both urls you can use this cookbook
Upvotes: 2