syed Posted August 1, 2010 Share Posted August 1, 2010 Hi guys, I am developing an MVC application and need some advice about how to set up url routing. Currently I can map a uri to modules/controllers and actions. I though I might leave the routing to last but it seems like that might have been a bad idea. Initially I though I might implement a Zend style routing approach and I still want to do this, but I am lost for thoughs on how I might go about this, I have looked at the zend router classes and understand the principle but cant seem to implement it in my own mvc. So far I have this, $router is an instance of a router class. mapRoute takes a route name and a route object as parameters. The name will be used for convinience. The second parameter takes a route instance which currently takes two parameters, where param1 is a route pattern and param2 is deafult values for when a uri macthes the route pattern. So if a user types http://example/user/23, the router should map to user controller, profile action. The id, which is 23, will need to be injected into a request object. Finally the router object will be added to a front controller instance, so the front controller object can gain access to all the routes. $router->mapRoute("user", new Route( "user/<id>", array( "controller"=>"user", "action"=>"profile" ) ) ); If any one has any ideas please do share, im not after code, unless you want to supply some, I just need some advice to stream line the whole process or what the best way might be. Any help will be greatly appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/209496-help-developing-a-basic-url-routing-for-mvc/ Share on other sites More sharing options...
trq Posted August 1, 2010 Share Posted August 1, 2010 There is a pretty good example here which I loosely used to build the routing in my framework. Quote Link to comment https://forums.phpfreaks.com/topic/209496-help-developing-a-basic-url-routing-for-mvc/#findComment-1093815 Share on other sites More sharing options...
syed Posted August 1, 2010 Author Share Posted August 1, 2010 Hi Thorpe, thanks for the article, explained a alot and set me on my way. I had this whole complex spliting and recursive check inmind. It never occured to me, to construct a regex pattern and compare it to the uri. Thanks for the article, you rock. Quote Link to comment https://forums.phpfreaks.com/topic/209496-help-developing-a-basic-url-routing-for-mvc/#findComment-1093833 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.