-- Sergio Rinaudo <[email protected]> wrote
(on Monday, 17 August 2009, 01:58 AM +0200):
> how to instance dispatcher and request objects in the bootstrap?

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
    protected function _initRouter()
    {
        $this->bootstrap('FrontController');
        $front = $this->getResource('FrontController');

        $dispatcher = $front->getDispatcher();
        $request    = $front->getRequest();

        // create routes...
    }
}


> > Date: Sun, 16 Aug 2009 16:57:09 -0400
> > From: [email protected]
> > To: [email protected]
> > Subject: Re: [fw-general] New Router Question
> >
> > -- milesap <[email protected]> wrote
> > (on Monday, 10 August 2009, 05:57 AM -0700):
> > > This is the first time I need to change the default Zend Router, so I want
> to
> > > make sure I'm doing it right. I need to have my links like so;
> > > http://register.example.com/companyname/controller/action.
> > >
> > > I looked on this forum and found a solution that might work:
> > >
> > > $route = new Zend_Controller_Router_Route(
> > > ':companyname/:controller/:action/*',
> > > array(
> > > 'module' => 'default',
> > > 'controller' => 'index',
> > > 'action' => 'index'
> > > )
> > > );
> > > $router->addRoute('newroute', $route);
> > >
> > > Is this the proper way to solve my problem? Finally, how would I be able 
> > > to
> > > determine the companyname in the link in my bootstrap file? Thanks so much
> > > for your help!
> >
> > If you will only have one module, yes, this will work. The companyname
> > will then be pushed into the request object, and you can grab it using
> > getParam('companyname').
> >
> > If *all* controllers will be accessed this way, I'd recommend you set
> > this as the "default" route (instead of "newroute"), to ensure that te
> > companyname identifier is required for all controller/action pairs.
> >
> > Finally, you should likely look into the route chaining mechanism:
> >
> > http://framework.zend.com/manual/en/zend.controller.router.html#
> zend.controller.router.routes.chain
> >
> > In this case, you would do something like this:
> >
> > $companyRoute = new Zend_Controller_Router_Route(':companyname');
> > $defaultRoute = new Zend_Controller_Router_Route_Module(
> > array(),
> > $dispatcher,
> > $request
> > );
> > $chainRoute = new Zend_Controller_Router_Route_Chain();
> > $chainRoute->chain($companyRoute)
> > ->chain($defaultRoute);
> >
> > $router->addRoute('default', $chainRoute);
> >
> > (You'll have to grab the dispatcher and request prior to this, obviously.)
> > The above has the advantage of also allowing multiple modules in your
> > application, while still requiring the companyname prefix.
> >
> > --
> > Matthew Weier O'Phinney
> > Project Lead | [email protected]
> > Zend Framework | http://framework.zend.com/
> 
> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
> Scatta, Scarica, Modifica... Condividi le tue foto con Windows Live!

-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to