I would like to know if this method of setting up routing in Zend Framework would be considered a reasonable approach – I am quite new to using ZF.
In my bootstrap file I have a method set up like this:
protected function _initRouting()
{
$zfc = Zend_Controller_Front::getInstance();
$router = $zfc->getRouter();
$router->addRoute(
'home',
new Zend_Controller_Router_Route(
'',
array(
'controller' => 'index',
'action' => 'index'
)
)
);
$router->addRoute(
'saveStory',
new Zend_Controller_Router_Route(
'save-story/:date/:seolink/:saveStory',
array(
'controller' => 'story',
'action' => 'index',
'saveStory' => 1
)
)
);
etc etc with all my routes.
This works fine and I like the clarity of specifying routes like this but have a nagging feeling that more experienced ZF programmers would tell me that it is not the best way and that I should not do it in the bootstrap and that I should specify the routes in a seperate config file. If this is the case what form would the config file take and how and where would I read it.
Any advice would be appreciated….Because my technique works this question is more a stylistic question – what is the most ‘elegant’ approach…..Thanks
It’s just down to personal preference. Like you, I prefer to define my routes in code, but some people prefer config files (and if you want to try this there are several examples in the manual).