0

I have a Zend application which has a CMS module and a User module. I need to do something in the CMS module's bootstrap that involves a service under the User module.

When I try to instantiate the service class, I get a "Class not found" error, suggesting that the resources in the Users module are not auto-loaded yet.

I want to stress that I have to do it during bootstrap, not after.

How can I possibly load a resource from my Users module from within the bootstrap of my Admin module?

tereško
  • 58,060
  • 25
  • 98
  • 150
Bez Hermoso
  • 1,132
  • 13
  • 20
  • You'll probably have to build a plugin to load the resources in the [preDispatch()](http://framework.zend.com/manual/en/zend.controller.plugins.html) or earlier. That way all of the bootstrap will have run – RockyFord May 11 '12 at 09:55
  • How are you currently loading your modules? Through resources.modules in application.ini or in the main bootstrap? – Tim Fountain May 11 '12 at 11:48

1 Answers1

0

You can perform the autoload of all required app classes and namespaces in the global bootstrap (and not in module specific bootstraps):

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    protected function _initAutoloaders()
    {

        // require / require_once for libs/modules with specific autoloaders

        // Load HTML purifier autoloader
        require_once 'HTMLPurifier' . DS . 'HTMLPurifier.auto.php';

        // Load WideImage
        require_once 'WideImage' . DS . 'WideImage.php';

        // ...

        // Use Zend autoloader for other stuff

        $zendAutoloader = Zend_Loader_Autoloader::getInstance();

        // Register stuff.
        $autoloader = array(new SomeClassLoader('SomeLib', LIB_PATH), 'loadClass');
        $zendAutoloader->pushAutoloader($autoloader, 'LibName\\');

        // ...


    }

    // ... Other initializers
}
faken
  • 6,572
  • 4
  • 27
  • 28