Zend 框架操作助手
我在 Zend Framework 动作助手方面几乎是新手,我尝试使用它们但没有成功(我读了很多关于动作助手的帖子,包括 http://devzone.zend.com/article/3350 并在大约 8 小时内找不到解决方案)。我使用 Zend Tool 来设置我的项目,助手的名称是 Action_Helper_Common。无论我做什么,我都会收到以下错误“致命错误:未找到类'Action_Helper_Common'”。目前,我的设置如下:
- zf 版本:1.11.3
- 助手名称:Action_Helper_Common
- 助手位置: /application/controllers/helpers/Common.php
在 Bootstrap.php 中我有以下功能:
protected function _initActionHelpers() {
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');
Zend_Controller_Action_HelperBroker::addHelper(
new Action_Helper_Common(null, $session)
);
}
我也尝试过但没有成功(它是在 _initActionHelpers 之前在 Bootstrap.php 中定义的):
protected function _initAutoloader() {
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/controllers/helpers'));
return $moduleLoader;
}
那么我做错了什么?!?!请PLZ帮忙,我很绝望,准备放弃:)
I'm pretty much newbie in Zend Framework action helpers and I am trying to use them with no success (I read a bunch of posts about action helpers, including http://devzone.zend.com/article/3350 and found no solution in like 8 hours). I used Zend Tool to setup my project and the name of the helper is Action_Helper_Common. No matter what I do, I get following error "Fatal error: Class 'Action_Helper_Common' not found". Currently, I have things set up like this:
- zf version: 1.11.3
- helper name: Action_Helper_Common
- helpers location:
/application/controllers/helpers/Common.php
In Bootstrap.php i have following function:
protected function _initActionHelpers() {
Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');
Zend_Controller_Action_HelperBroker::addHelper(
new Action_Helper_Common(null, $session)
);
}
I also tried this without success (it was defined in Bootstrap.php before _initActionHelpers):
protected function _initAutoloader() {
$moduleLoader = new Zend_Application_Module_Autoloader(array(
'namespace' => '',
'basePath' => APPLICATION_PATH . '/controllers/helpers'));
return $moduleLoader;
}
So what am I doing wrong?!?! PLZ help, I am desperate and about to give up :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您收到错误,因为您尚未为 Action_Helper_* 设置自动加载器
资源自动加载器
Helper Broker 使用插件加载器根据您为其指定的路径和前缀加载助手。这就是为什么 ::getHelper() 可以找到你的帮手
You got error because you haven't setup autoloader for Action_Helper_*
Resource autoloader
Helper broker uses plugin loader to load helpers based on paths and prefixes you specified to it. That is why ::getHelper() can find your helper
你不需要这样做(所以删除它),
因为你已经这样做了
执行时,zf 将在目录 /controllers/helpers/ 中查找类名 Action_Helper_Common 并为你创建一个实例并返回它。
,当你在控制器中
you dont need to do (so remove it)
since you already did
when you will do
in your controller zf will lookinto directory /controllers/helpers/ for class name Action_Helper_Common and create an instance for you and return it.
由于某种原因,以下行对我也不起作用:
每次我显式创建新的辅助对象时,我都会收到“未找到类”错误。
这对我有用:
在这种情况下,新的
Action_Helper_Common
对象被创建并注册到Helper Broker
。但不确定它是否适合您,因为您有一个参数化构造函数。
For some reason the following line didn't work for me as well:
I just keep getting a 'Class not found' error each time I'm creating a new helper object explicitly.
This is what works for me:
In this case, new
Action_Helper_Common
object gets created and is registered withHelper Broker
.Not sure though if it works for you, since you have a parameterized constructor.