开发者

All module bootstraps always run on one request

I have two modules: admin, default. Each has one bootstrap:

class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{
     function _initSmth()
     {
          echo 'admin';
          die();
     }
}

and the default one:

 class Default_Bootstrap extends Zend_Application_Module_Bootstrap
    {
         function _initSmth()
         {
              echo 'default';
              die();
         }
    }

If I run site.ru or s开发者_StackOverflow中文版ite.ru/admin/ it always returns 'admin'. Why default bootstrap run with admin bootstrap?


Yes, this is the way Zend works. If you enable module resource into your application config (tipically application.ini)

resource.modules=

All the modules are bootstrapped at bootstrap time. If you want to switch behaviors based on which module the request has been routed to you can plan using controllers plugin.

Consider that the first hook that is aware of which module/controller/action is the routeShutdown but depending what you need to do you can use other hooks.

Here is an example

Plugin_Test extends Zend_Controller_Plugin_Abstract {

public function routeShutdown (Zend_Controller_Request_Abstract $request){

    switch($request->getModuleName()) {

        case 'default':
        // do something
        break;
        case 'admin':
        // do something else
    }

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜