0

我尝试在 Zend_Layout 选项中使用 helperClass。我创建一个类:

class Helper_Testi extends Zend_Controller_Action_Helper_Abstract{

    public function init(){
        echo "111111111";
        $this->fff = 'hello from Helper';
    }

    public function getMessage(){
        echo "==============";
        return "message";
    }
}

并在 Bootstrap.php 中尝试将其添加到 Zend_Layout:

$options = array('layout' => 'layout','helperClass'=>'../application/controllers/helper/Testi');
$layout = new Zend_Layout();
$layout->startMvc($options);

但是当我重新加载浏览器时,我看到了异常:

Fatal error: Uncaught exception 'Zend_Exception' with message 'File "../application/controllers/helper/Testi.php" does not exist or class "../application/controllers/helper/Testi" was not found in the file'

我做错了什么?请帮帮我。

4

2 回答 2

0

你需要把你的助手类放在正确的地方。

例如,在我的引导程序中有这样的行:

protected function _initViewHelpers() {
    $this->bootstrap('layout');
    $layout = $this->getResource('layout');
    $view = $layout->getView();

    $view->addHelperPath('Icc/View/Helper' , 'Icc_View_Helper');
}

帮助文件将位于此文件夹中:Icc\View\Helper\


编辑:

例如,我有FormDropdown.php 这样内容的文件:

class Icc_View_Helper_FormDropdown extends Zend_View_Helper_Abstract {
    function formDropdown($name = '')
    {
       return "<select name='$name' id='$name'></select>";
    }
}

鉴于我可以通过这种方式使用这个助手:

    <?=$this->formDropdown('icc_info_salutation')?>
于 2011-07-12T15:18:05.777 回答
0

尝试在路径中使用 APPLICATION_PATH 常量

于 2011-07-12T15:58:04.907 回答