I know this is an old question, but I had a similar problem, and I thought I should post my solution. Perhaps this can help other people consider this issue.
I wrote my routes in the plugin. Obviously you need to add the plugin to bootstrap for this to work;)
class Plugin_RoutesPage extends Zend_Controller_Plugin_Abstract { public function routeStartup(Zend_Controller_Request_Abstract $request) { $front_controller = Zend_Controller_Front::getInstance(); $router = $front_controller->getRouter(); // Page SEO friendly hierarchical urls $routePageSeoTree = new Zend_Controller_Router_Route_Regex( '([-a-zA-Z0-9/]+)/([-a-zA-Z0-9]+)', array( // default Route Values 'controller' => 'page', 'action' => 'open', ), array( // regex matched set names 1 => 'parents', 2 => 'item' ) ); $router->addRoute('page-seo-tree',$routePageSeoTree); // only one level $routeSinglePage = new Zend_Controller_Router_Route_Regex( '([-a-zA-Z0-9]+)', array( // default Route Values 'controller' => 'page', 'action' => 'open', ), array( // regex matched set names 1 => 'item' ) ); $router->addRoute('page-single',$routeSinglePage); } }
Here's how you can use it in your controller action.
class PageController extends Zend_Controller_Action { public function openAction() {
Here is a quick example of how to include it in your bootstrap
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap { protected function _initPlugins() { $front_controller = Zend_Controller_Front::getInstance(); $front_controller->registerPlugin(new Plugin_RoutesPage(), 1); } }
I had to use two routes, because the current page that we are trying to view / open may not have parents. I am sure that probably the best way to write a regex, but this is what worked for me. If anyone knows how to improve regex, please let me know.
source share