开发者

What are the different ways to configure routes?

If someone is familier with Zend Framewor, they know what routes are and how they affect the system overall. My question is concerned about ways to can configure this rout开发者_如何学Pythones. I know two ways to configure them, through Bootstrap.php and application.ini.

However, not hiding the fact that, I am pretty much of a learner in Zend Framework myself, I dont know which one is better and which should be preferred over the other.

Moreover, I do not know, if these are only ways available to configure the router?

So, please tell me what are ways through which we can configure router and which method is better over others.

P.S: I have included the two ways I knew as an answer.


Routing is an configuration which doesn't get change at runtime hence its better to put in configuration file separating from code which is dynamic . Define router in Bootstrap.php if your router depends upon some condition which is dynamic in nature .


Since I am attempting this to be as a guide for those like me, I would like to include the two ways I know of.

Application.ini

resources.router.routes.cat.route = "/browse/:catid/:name/"
resources.router.routes.cat.defaults.controller = index
resources.router.routes.cat.defaults.action = browse

Here What you do is, resources.router.routes.XXX.route Define the name of the route in place of XXX

catid and name are the two paramters that will taken, when you pass the url is such way /browse/1/pc 1 will be assinged to catid and pc to name

Remaining two line defines the default parameter from controller and action, from MVC

Bootstrap.php

    $front = Zend_Controller_Front::getInstance();  
    // Get Router
    $router = $front -> getRouter();
    $routeBrowse = new Zend_Controller_Router_Route(
        '/browse/:catid/:name',
        array(
            'controller' => 'index',
            'action' => 'index'
        )
    );
    $router -> addRoute('browse', $routeBrowse);

I will avoid the explanation, since pretty much is same as before.

However, I am not sure which one is better that the other one. So, those who knows, update my answer.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜