0

I try to use plugin to dispatch bootstraps for different modules. However, for some reason, I can not trigger controller for each module, and the error is "EXCEPTION_NO_CONTROLLER". Any one could give some advice about it?

// Plugin Code:
class Plugin_AccessCheck extends Zend_Controller_Plugin_Abstract {
    public function __construct() {
    }

    public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request) {
        if ('admin' == $request->getModuleName()) {
            require_once APPLICATION_PATH .'/modules/admin/Bootstrap.php';
            $moduleBootstrap = new Admin_Bootstrap();
            $moduleBootstrap->bootstrap();
        } else if('site' == $request->getModuleName()) {

        }
    }
}

// Module Bootstrap:
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap{    
    public function Admin_Bootstrap() {
    }

    protected function _initAutoload() {
        define("localhost", "adrian");
    }
}
1
  • 1
    I don't think ZF1 works the way you think it does. Commented Jan 9, 2013 at 10:10

2 Answers 2

2

All module bootstraps are run on every request.

If there is some processing you wish to perform when the request is routed to single module, then register a plugin - either in application bootstrap or in module bootstrap; as noted above, they will all run - that exits early if the request is not targeted at his module.

See this post by MWOP for further discussion:

http://www.mwop.net/blog/234-Module-Bootstraps-in-Zend-Framework-Dos-and-Donts.html

Sign up to request clarification or add additional context in comments.

Comments

1

Im not sure..if i unserstand your question..you can try

public function dispatchLoopStartup(Zend_Controller_Request_Abstract $request)
{
   $request = Zend_Controller_Front::getInstance()->getRequest();
    if ('admin' == $request->getModuleName()) {

        require_once APPLICATION_PATH.'/modules/admin/Bootstrap.php';

        $moduleBootstrap = new Admin_Bootstrap();

        $moduleBootstrap->bootstrap();

    }
    else if('site' == $request->getModuleName()){
               $request->setModuleName('othermodule');
                $request->setControllerName('othercontroller');
                $request->setActionName('otherindex');
    }
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.