Zend 框架操作助手

发布于 2024-10-20 03:35:12 字数 1122 浏览 7 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

罗罗贝儿 2024-10-27 03:35:12

您收到错误,因为您尚未为 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

つ可否回来 2024-10-27 03:35:12

你不需要这样做(所以删除它),

Zend_Controller_Action_HelperBroker::addHelper(
        new Action_Helper_Common(null, $session)
    ); ,

因为你已经这样做了

Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');

执行时,zf 将在目录 /controllers/helpers/ 中查找类名 Action_Helper_Common 并为你创建一个实例并返回它。

$myhelper = $this->getHelper('Common');

,当你在控制器中

you dont need to do (so remove it)

Zend_Controller_Action_HelperBroker::addHelper(
        new Action_Helper_Common(null, $session)
    ); ,

since you already did

Zend_Controller_Action_HelperBroker::addPath(APPLICATION_PATH . '/controllers/helpers', 'Action_Helper');

when you will do

$myhelper = $this->getHelper('Common');

in your controller zf will lookinto directory /controllers/helpers/ for class name Action_Helper_Common and create an instance for you and return it.

圈圈圆圆圈圈 2024-10-27 03:35:12

由于某种原因,以下行对我也不起作用:

Zend_Controller_Action_HelperBroker::addHelper( new Action_Helper_Common() );

每次我显式创建新的辅助对象时,我都会收到“未找到类”错误。

这对我有用:

Zend_Controller_Action_HelperBroker::getHelper('Common');

在这种情况下,新的 Action_Helper_Common 对象被创建并注册到 Helper Broker

但不确定它是否适合您,因为您有一个参数化构造函数。

For some reason the following line didn't work for me as well:

Zend_Controller_Action_HelperBroker::addHelper( new Action_Helper_Common() );

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:

Zend_Controller_Action_HelperBroker::getHelper('Common');

In this case, new Action_Helper_Common object gets created and is registered with Helper Broker.

Not sure though if it works for you, since you have a parameterized constructor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文