Jump to content

URL Router Suggestions


punk_runner

Recommended Posts

We're building our own little MVC-ish framework for client projects. It's just two of us here and we do about four medium sized projects a year (100k to 500k users)... I have the router all built but now I am second guessing the way my URL paths are laid out. Currently they are in this format:

 

www.domain.com/controller/action/argument1/argument2

 

I pull the domain off of the string with substr() and then explode the rest at the slashes, and set $bit[0] to the controller, $bit[1] to the action and pass the rest to the controller as an array and deal with it there. Works great.

 

I'm just curious if anyone has any advice or input on doing this, is there a better way, a better URL format to use? For example, one of our URL's may look like this:

 

www.domain.com/user/view/bsmith/photos

 

and the User_Controller has a method called viewUser that knows that the first argument is the username and the second one is the page to display...

 

Is this an acceptable way to do this on a non-distributed framework, or is there a better way?

Link to comment
Share on other sites

I've just finished the initial development of my own Router component for my framework 'Proem' that you might want to take a look at.

 

Nothing is documented as yet but looking at the tests should pretty much describe the functionality.

 

http://codaset.com/trq/proem/source/route-dispatch/blob/tests/lib/Proem/Controller/RouterTest.php

 

Basically, the Router can use many different types of Route objects, currently there are 3 implemented.

 

 

  • Fixed - Directs every request to a specific controller and action, passes all other params untoched.
  • Standard - Maps /controller/action/param1/value1/param2/value2, similar to your implementation.

 

Then there is a 'Map' type Route. The Map Route allows you to map urls to named params very similar to how Zend's standard router works. See the above link for examples.

 

The Map type is by far the most flexible and will likely get the most use, the other two where only built for speed and might come in handy on occasion.

 

I haven't yet implemented any Dispatch yet, so all the Router does is return a Command object which contains all the controller, action and params data at present. It's all still very much a work in progress.

 

Anyway, it might give you a few ideas.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.