Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Routing in Symfony2

Tags:

How to setup default routing in Symfony2?

In Symfony1 it looked something like this:

homepage:   url:   /   param: { module: default, action: index }  default_symfony:   url:   /symfony/:action/...   param: { module: default }  default_index:   url:   /:module   param: { action: index }  default:   url:   /:module/:action/... 
like image 529
umpirsky Avatar asked Feb 09 '11 13:02

umpirsky


1 Answers

I was looking through the cookbook for an answer to this, and think I've found it here. By default, all route parameters have a hidden requirement that they match any character except the / character ([^/]+), but this behaviour can be overridden with the requirements keyword, by forcing it to match any character.

The following should create a default route that catches all others - and as such, should come last in your routing config, as any following routes will never match. To ensure it matches "/" as well, a default value for the url parameter is included.

default_route:     pattern: /{url}     defaults: { _controller: AcmeBundle:Default:index, url: "index" }     requirements:         url: ".+" 
like image 145
Longsight Avatar answered Sep 29 '22 07:09

Longsight