Dear Zend Framework users,

In the multi-account application I am working on, a user may access its 
application either by:
http://<account>.app.domain.com/<module>/<controller>/<action>
or:
http://app.domain.com/<account>/<module>/<controller>/<action>

To do so, I wrote this bootstrap method:

    public function _initRoutes()
    {
        $front = Zend_Controller_Front::getInstance();
        $router = $front->getRouter();

        $defaultRoute = new Zend_Controller_Router_Route(
            ':account/:module/:controller/:action/*',
            array(
                'account'    => 'demo',
                'module'     => 'default',
                'controller' => 'index',
                'action'     => 'index'
            ),
            array('account' => '([a-z0-9]+)')
        );
        $router->addRoute('default', $defaultRoute);

        $pathRoute = new Zend_Controller_Router_Route(
            ':module/:controller/:action/*',
            array(
                'module'     => 'default',
                'controller' => 'index',
                'action'     => 'index'
            )
        );
        $hostnameRoute = new Zend_Controller_Router_Route_Hostname(
            ':account.app.domain.com',
            array('account' => 'demo'),
            array('account' => '([a-z0-9]+)')
        );
        $router->addRoute('hostname', $hostnameRoute->chain($pathRoute));
    }

Everything was ok, until I wanted to add a REST route for a whole module named 
"rest".
Adding the following at the end of the function consume the :account parameter that is never obtained by the first route :

        $restRoute = new Zend_Rest_Route(
            $front,
            array(),
            array('rest')
        );
        $accountRoute = new Zend_Controller_Router_Route(
            ':account',
            array('account' => 'demo'),
            array('account' => '([a-z0-9]+)')
        );
        $router->addRoute('default', $accountRoute->chain($restRoute));

What is the solution?
--
Guillaume ORIOL
Software engineer
Technema

Reply via email to