问题
I have a very strange case where my Module is working but my Module's boostrap is not being loaded.
Here is the segment in my application.ini for module autoloading:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
Here is the bootstrapper:
protected function _initAutoload()
{
$autoloader = new Zend_Application_Module_Autoloader(array(
'namespace' => 'User_',
'basePath' => APPLICATION_PATH .'/modules/user',
'resourceTypes' => array (
'model' => array(
'path' => 'models',
'namespace' => 'Model',
)
)
));
}
Structure of my modules
Application
--modules
----user
------config/
------controllers/
------models/
------views/
------Bootstrap.php
----admin
The problem here is that User_Bootstrap is not being loaded.
<?php
class User_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initAutoload()
{
Zend_Registry::set('debug', 'haha');
}
}
By doing a Zend_Registry::get('debug') on any controller, it doesn't recognize that the key was set in the module bootstrap. In fact any syntax error in the User_Bootstrap does not work.
I don't know why User_Bootstrap is not being autoloaded. This is driving me crazy because I've been researching for 5 hours and can't even get a blog post close to covering this case...
Speaking of which, my models and controller classes are being autoloaded fine.
回答1:
Try the following...
Change your
application.ini
file to use; lose the quotes resources.modules[] =
See http://framework.zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.modules
Remove the
_initAutoload()
method from your ApplicationBootstrap
class. You don't need this as the module bootstrap will automatically create a resource loader for yourUser_
classes
回答2:
Not sure but it might as simple as improper case.
--Modules
is in your structure but you keep referring to it as /modules
. These should match case.
I hope it's that simple.
Don't duplicate the function names of your main bootstrap in your module bootstrap, as far as I know in ZF 1.x all of the boostraps get processed every call and I think your _initAutoload in the main boostrap is overriding the module bootstrap.
try calling your function some different like _initModuleAutoload.
At least worth a shot :)
回答3:
Have you tried disabling frontController directory in application.ini config file? Try commenting/deleting this line:
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
来源:https://stackoverflow.com/questions/9371615/zend-module-bootstrap-does-not-load