开发者

Building page urls in php application

I'm running my own extremely light MVC framework (without Router class). To know what controller and action to run I'm using library or regexps applied to REQUEST_URI. Something like...

$regexps = array(
    '/admin/categories/' => array(开发者_如何学Python
        'controller' => 'AdminCategories', 
        'action'     => 'index'
    ),
    '/admin/categories/add/' => array(
        'controller' => 'AdminCategories',
        'action'     => 'add'
    ),
);

Everything works fine, BUT...

What is the best practice to BUILD urls?

BuildUrl('Controller', 'action', array('var1' => 'val1', 'var2' => 'val2'));

What is the best practice to modify current url (for, example I have table with 10 different filtering options)?

ModCurrentUrl(array(...));

How do you solve this problem in your applications?

PS: I'm not using conroller's action parameters, all parameters are taken from $_GET.

Thank you and sorry for my English.


Best practice ( as i see it ) would be to have a library called Routing ( basicly a class ) with static methods . You can then use Routing::buildUrl(...) , and fill it with all uri related methods you'll use ( like modCurrentUrl ... )


Here is couple good links for you: http://robap.github.com/php-router/ http://code.google.com/p/routemap/ And i don't see any signs of subdirectories in your example. In big projects it could be fine. Firstly request get to the router class' method, from there you get some actual data about the route. Secondly you put this data to a dispatcher which is starting your application.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜