What are the different ways to configure routes?
Question by Starx
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 routes. 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.
Answer by Starx
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.