views:

181

answers:

2

This is kind of an academic question, so feel free to exit now. I've had a dig through Stack for threads pertaining to URL/Controller mapping in MVC frameworks - in particular this one:

http://stackoverflow.com/questions/125677/php-application-url-routing

So far, I can ascertain two practices:

1: dynamic mapping through parsing the URL string (exploded on '/')

2: pattern matching matching url to config file containing available routes

I wanted to get some feedback (or links to some other threads/articles) from folks regarding their views on how best to approach this task.

A: 

I use your first option.

www.mysite.com/section1

this will be exploded and in one file I will check to see if a controller named section1 is on the server if it is then I use that to figure out what is suppose to happen if there is no controller then I look to see if there is a static file with this name and serve that up if the script still cannot find anything it serves a 404 page with some helpful information. This has worked great for me and gives me alot of control over how the site reacts to different situations.

Donniep
+1  A: 

You can mix both options. Most frameworks do it to manage URL mapping. The first one is the default and the second one is the alternative. One php framework that uses it is Zend. you may check out zend_router for more details.

Hanseh
thanks for the answer.my experience with ZF is the reason I'm experimenting with this method - but it's router class is a little impenetrable for me if I'm honest. I've resorted to some simple string parsing, and may implement a config file fallback following your feedback.
sunwukung