writing an effective router/dispatcher for mvc pattern ??

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

writing an effective router/dispatcher for mvc pattern ??

Post by PHPycho »

hello forums !!
I am trying to make an router/dispatcher for oo mvc pattern.
I would like to have one default router pattern ie controller/method/id and other is customized one
for example

Code: Select all

http://yoursite.com/controller/method/id/params => $controller->method($id[, $params])(general)
http://yoursite.com/admin/controller/method/id/params => $controller->admin_method($id[, $params]) (customized)
Can anybody provide good suggestions/samples in dispatching such method.
Note: dispatching method should work both for url rewriting turned on or off by changing some flags.

Thanks in advance for your valueable suggestions.
ynwa
Forum Newbie
Posts: 5
Joined: Wed Jan 23, 2008 8:42 am

Re: writing an effective router/dispatcher for mvc pattern ??

Post by ynwa »

User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Re: writing an effective router/dispatcher for mvc pattern ??

Post by PHPycho »

Knock Knock... Can anybody come with better ideas
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: writing an effective router/dispatcher for mvc pattern ??

Post by Christopher »

You are asking a couple of huge design questions. The article above is a good intro to Dispatchers. You can take a look at code like Horde Routes for a router. Are you looking for simple or complex. You did not mention a Front Controller, but that is implicit in the discussion. And, Front Controller and Routers are really separate from MVC. The dispatched Action Controller is really the MVC part in modern architectures.

Given that it is such a broad subject ... is there something specific you would like to start with?
(#10850)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: writing an effective router/dispatcher for mvc pattern ??

Post by s.dot »

This exact question is what has stopped me in my progress on going totally OOP.

Of course, I don't mean literally stopped. I still read tons of articles and write practice code to experience different situations with what I already know.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Re: writing an effective router/dispatcher for mvc pattern ??

Post by Kieran Huggins »

I've been swayed to the front controller camp, and also away from mod_rewrite. I'm still "finding myself" as it were when it comes to routing in PHP, but I've been thinking a lot more about using regex expressions. I think symfony uses this approach, so that might be a good starting place for inspiration.
User avatar
Oren
DevNet Resident
Posts: 1640
Joined: Fri Apr 07, 2006 5:13 am
Location: Israel

Re: writing an effective router/dispatcher for mvc pattern ??

Post by Oren »

PHPycho wrote:Knock Knock... Can anybody come with better ideas
What's wrong with this one?
Post Reply