The reason I ask this is because isn't a PHP script a route? For example, if you have an article.php then your route is simply http://mysite.com/article.php. Why further abstract away the concept of a route when it already exists as a simple file? |
|||
add a comment
|
To understand what a router does, you must first understand what a rewrite engine is. From theWikipedia article (emphasis mine):
When a rewrite engine is used you don't have an 1:1 correlation between the URL and a PHP script. An example from the same article:
There are various benefits to using the technique. Since PHP is usually tightly coupled with Apache, the most commonly used rewrite engine is Apache's mod_rewrite. If you want rewritten URLs, you need some kind of routing, as routing is the process of taking the URL, braking it into components and deciding what is the actual script to call. The documentation page for the standard router of the Zend Framework explains the process as:
Most PHP frameworks nowadays are based on the MVC pattern, and on an MVC framework the process goes something like this*:
Matching parameters to controllers and methods usually employs matching via regular expressions to be able to handle complex and dynamic routing patterns, known as routes. Good examples of routes can be found on CodeIgniter's URI Routing documentation page:
The *This is not intended as a description of the canonical process, just an oversimplified explanation. |
|||||||||
|