7

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:

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.

Community
  • 1
  • 1
sunwukung
  • 2,815
  • 3
  • 41
  • 56
  • 2
    What is your question? You've given your research and your tries, but no question? – Arda Xi Apr 11 '10 at 22:02
  • I'm asking for feedback on methods of mapping URL's to controllers, either from the StackOverflow user base, or by reference to other articles/threads that they have found useful. – sunwukung Apr 12 '10 at 07:38

2 Answers2

4

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.

vatavale
  • 1,470
  • 22
  • 31
Hanseh
  • 717
  • 4
  • 17
  • 1
    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 Apr 13 '10 at 10:27
0

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
  • 39
  • 1
  • 6