Zend 1 php 如何获取助手并在 class 之外执行它?

Zend 1 php how to get helper and execute it outside of the class?

我需要能够在 php 调试工具中执行此代码:

 $magicStuff = $this->getHelper('magic')->doMagic();

我有一个助手,我需要在 PHP 调试工具中执行它。出于这个原因,我需要“调用”这个助手才能使用。

我试过了,但似乎strong text 遗漏了一些东西。我是 Zend 的新手,非常感谢您的帮助。

magic.php

/**
 * Helper declared in the actions/helpers/magic.php file
 */
class Magic_Controller_Helper extends Zend_Controller_Action_Helper_Abstract
{

    /**
     * Do some magic and return data.
     *
     * @return array
     */
    public function doMagic()
    {
        return $getStuff;
    }
}

我试过:

$helper = Zend_Controller_Action_HelperBroker::getHelper('magic');
$results= $helper->doMagic();
var_dump($results);

我回来了:

Action helper "magic" has not been registered with the helper broker
Exception:
Message: Action helper "magic" has not been registered with the helper broker
   Code: 0

您可能错过了您的库名称空间和 actionhelper 路径的注册。 在您的 application.ini 中添加以下内容

resources.frontController.actionhelperpaths.Magic_Controller_Action_Helper = "Magic/Controller/Action/Helper"

autoloadernamespaces.Magic = "Magic_"

“魔法”库应该存在于“库”文件夹下。 如果您在“Action”命名空间下没有您的助手,请尝试将其删除

resources.frontController.actionhelperpaths.Magic_Controller_Helper = "Magic/Controller/Helper"