punk_runner Posted January 12, 2011 Share Posted January 12, 2011 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? Quote Link to comment https://forums.phpfreaks.com/topic/224206-url-router-suggestions/ Share on other sites More sharing options...
trq Posted January 12, 2011 Share Posted January 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/224206-url-router-suggestions/#findComment-1158598 Share on other sites More sharing options...
trq Posted January 14, 2011 Share Posted January 14, 2011 An update, I'm this thing to github. https://github.com/trq/proem/blob/route-dispatch/tests/lib/Proem/Controller/RouterTest.php Quote Link to comment https://forums.phpfreaks.com/topic/224206-url-router-suggestions/#findComment-1159229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.