Route all requests through PageController except existing controllers (Zend Framework)

Posted by ChrisRamakers on Stack Overflow See other posts from Stack Overflow or by ChrisRamakers
Published on 2010-03-25T23:05:29Z Indexed on 2010/03/25 23:13 UTC
Read the original article Hit count: 414

Filed under:
|
|

For a new CMS i've developed a Pages module that allows me to manage the site's tree structure. Each page is reachable from the url http://www.example.com/pageslug/ where pageslug identifies the page being called.

What I want to achieve now is a route that allows me to route all incoming requests to a single PagesController unless it's a request to an existing controller (like images for example).

It's easy enough to catch all requests to the Pages Controller but how to exclude existing controllers? This is my module bootstrap. How can i achieve this in the most preferrable way

<?php

class Default_Bootstrap extends Zend_Application_Module_Bootstrap
{

    protected function _initRoute()
    {
        $this->bootstrap('frontController');

        /* @var $frontcontroller Zend_Controller_Front */
        $frontcontroller = $this->getResource('frontController');

        $router = $frontcontroller->getRouter();
        $router->addRoute(
            'all',
            new Zend_Controller_Router_Route('*',
                array('controller' => 'pages',
                      'action'     => 'view')
            )
        );

    }

}

© Stack Overflow or respective owner

Related posts about php

Related posts about zend-framework