How can someone autoload each form and model for each module? Consider the following file structure:
application/ modules/ foo/ forms/ Register.php models/ Account.php Bootstrap.php bar/ forms/ Publish.php models/ Article.php Bootstrap.php Bootstrap.php
And, for example, in foo / Bootstrap.php you have the following ( non-functional ) code:
class Foo_Bootstrap extends Zend_Application_Module_Bootstrap { protected function _initAutoLoad() { $loader = new Zend_Loader_Autoloader_Resource(array( 'basePath' => APPLICATION_PATH . '/modules/foo', 'namespace' => 'Foo', )); $loader->addResourceType('form', 'forms', 'Form') ->addResourceType('model', 'models', 'Model'); return $loader; } }
The main question . How can I modify the bootstrap so that it loads each form and model from the Foo module?
Additional question . Is it possible to have a global autoloader that loads in forms and models from each module? If so, how?
Edit (most common questions about the problem):
The standard Zend naming conventions are used for classes. For example, Bar_Model_Article , Bar_Model_Mapper_Article , Bar_Model_DbTable_Article , Bar_Form_Publish , ... (And are placed in their corresponding folder.)
This is not only one module that does not load its classes, but thatβs all.
There are no problems with autoload classes using the Zend autoloader when using a simple non-modular application with several models, maps, dbtables and forms.
Fix
As @Tim Fountain said, the bootstraps module did not start, which means that when loading in Zend, the automatic loading did not occur. In the end, I found that the problem was in my case. I had to remove the following lines from my configuration:
bootstrap.path = APPLICATION_PATH "/Bootstrap.php" bootstrap.class = "Bootstrap"
I agree the global bootstrap will no longer work; but it is much better than the bootstraps module does not work. If anyone knows how to still have a global bootstrap, feel free to leave a comment. Hope this can help others with a similar problem.