Let’s look at two identhical routes, one described in symfony 1.4:
1 2 3 4 5 | |
and the other one in Symfony2:
1 2 3 4 5 | |
as you see there are a few changes, so let’s compare them line after line!
You ain’t gonna need the @ anymore
The symfony 1.X routing system was mainly identifying the routes through the @ prefix.
That was also the way to write faster routes:
1 2 | |
With the new routing system you’ll be only able to reference the plain route name:
1 2 3 4 | |
Effectively working patterns
Once you describe your routing pattern, for example:
1
| |
Symfony will be able to incapsulate and isolate the request object, the controller and the needed parameters.
No more sfWebRequest’s hyper-referencing to get any routing parameter:
1 2 3 4 5 | |
they are directly injected to your action:
1 2 3 | |
From YAML to PHP
The localization of the proper action able to handle the matched route is not a params array anymore.
Since Symfony2 introduced multiple controllers per bundle, you need to specify, in one parameter, the bundle, the controller and the action:
1
| |
Internals
As you’ve seen, there is no sHell..ops, sf prefix for any internal convention.
For example, when requiring a request method, you need to specify the _method parameter, not the sf_method anymore.
Multiple request methods
When dealing with some URLs ( ie. /posts ) you want to let the resource being asked with different verbs, such as GET to get the entire posts collection, POST for inserting a new one… etc etc…
In symfony 1.X the methods were described as a YAML array:
1
| |
while in Symfony2 you have a slightly different syntax:
1
| |
which banally reminds us the native language statements/operators:
1
| |