Zend 模块引导程序未加载
我有一个非常奇怪的情况,我的模块正在工作,但我的模块的 boostrap 没有被加载。
这是我的 application.ini 中用于模块自动加载的部分:
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.modules[] = ""
这是引导程序:
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',
)
)
));
}
我的模块的结构
Application
--modules
----user
------config/
------controllers/
------models/
------views/
------Bootstrap.php
----admin
这里的问题是 User_Bootstrap 没有被加载。
<?php
class User_Bootstrap extends Zend_Application_Module_Bootstrap
{
protected function _initAutoload()
{
Zend_Registry::set('debug', 'haha');
}
}
通过在任何控制器上执行 Zend_Registry::get('debug') ,它无法识别该密钥是在模块引导程序中设置的。事实上,User_Bootstrap 中的任何语法错误都不起作用。
我不知道为什么 User_Bootstrap 没有被自动加载。这让我发疯,因为我已经研究了 5 个小时,甚至无法获得一篇博客文章来接近这个案例……
说到这里,我的模型和控制器类正在自动加载得很好。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
尝试以下操作...
更改要使用的
application.ini
文件<前><代码>;失去引号
资源.模块[] =
请参阅http://framework。 zend.com/manual/en/zend.application.available-resources.html#zend.application.available-resources.modules
删除应用程序
Bootstrap
类中的_initAutoload()
方法。您不需要这个,因为模块引导程序会自动为您的User_
类创建资源加载器Try the following...
Change your
application.ini
file to useSee 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不确定,但这可能就像不正确的情况一样简单。
--Modules
位于您的结构中,但您一直将其称为/modules
。这些应该匹配大小写。我希望事情就这么简单。
不要在模块引导程序中重复主引导程序的函数名称,据我所知,在 ZF 1.x 中,所有引导程序都会在每次调用时得到处理,并且我认为主引导程序中的 _initAutoload 正在覆盖模块引导程序。< br>
尝试调用一些不同的函数,例如 _initModuleAutoload。
至少值得一试:)
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 :)
您是否尝试过在 application.ini 配置文件中禁用 frontController 目录?尝试注释/删除此行:
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
Have you tried disabling frontController directory in application.ini config file? Try commenting/deleting this line:
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"