I have come across a strange problem with Zend_Framework, I can not load forms or models from any module other than default.
I have the following line of code in my controller (in the user module)
$myAccountModel = new User_Model_MyAccount();
However all i get is the error
Fatal error: Class 'User_Model_MyAccount' not found in F:\My Webs\freedate\application\modules\user\controllers\MyAccountController.php on line 13
I have checked the files path and class name and all is correct, I have this project setup similar to other ZF projects I have done in the past, the only difference is that this is on a WAMP server rather than a LAMP server.
If I try to load a model or form from the default module it loads fine, these line of code produce no errors and the classes load fine.
$loginForm = new Form_Login();
$loginModel = new Model_Login();
If someone can shed some light as to what is going on here it would be most helpful as I have now hit a brick wall!!
I am using ZF 1.11.11 btw.
Many thanks
Garry
[EDIT]
This is definatly a probelm with ZF autoloader, if I add the following line the error goes away.
require_once(APPLICATION_PATH . '/modules/user/models/MyAccount.php');
In my application.ini i have
; modules
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] =
and in my bootstrap.php I have
/** * Initialize autoloader
* @return Zend_Loader_Autoloader
*/
protected function _initAutoload() {
return Zend_Loader_Autoloader::getInstance();
}
/** * Initialize module autoloader
* @return Zend_Application_Module_Autoloader
*/
protected function _initModuleAutoload() {
$modelLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/modules/default'));
return $modelLoader;
}
Have you tried to add an empty Module_Bootstrap to the specific module? Like so:
Once you do this, you can remove the
_initAutoload()and_initModuleAutoload()methods from your bootstrap. When you create a module bootstrap, the Zend_Application_Module_Autoloader is automatically created by default for that module.See The Module Resource Autoloader