Blog
On URL routing, actions and ID parameters
2007-08-29 15:12:26 by Martynas Jusevičius
Many Web frameworks these days (e. g. Symfony, which is one of the more popular ones) are listing URL routing (sometimes also called mapping) as an important feature. Routing basically rewrites URLs with parameters into more user-friendly URLs, most likely hierarchical ones. For example:
http://www.example.com/index.php?category=2&page_id=3&action=view
after routing might become:
http://www.example.com/news/today
Symfony uses a special routing.yml configuration file, a PHP layer and also Apache's URL rewriting behind it to implement routing.
With the DIY Framework, URL routing as in Symfony is simply not necessary. It works another way:
- No physical .php files (except for one front controller for each application) are directly accessed from the web, so there is no need to hide them. All the code has to belong to classes and there can only be a single entry and output point in the application. Moreover, URLs are completely independent from Resources and the code that handles them.
- No action parameters are needed, since there is no concept of some abstract action. Resources are RESTful and simply implement HTTP methods.
- No ID parameters are needed to identify pages or Model objects (e. g. products or users) since these relationships are already known at the PHP and database levels. Model tables and classes are related to the appropriate Resources as defined in Propel's schema.xml.
That said, there is no need for some proprietary routing configuration and also no performance cost from the routing layer. Moreover, there are by design no potential security breaches such as passing wrong IDs. Symfony instead tries to cover them with URL routing.
