Zend 1.11 + Cannot use a module resource from within another module's bootstrap

148 Views Asked by At

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?

1

There are 1 best solutions below

0
On

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
}