我如何在zend中添加视图助手

我如何在zend中添加视图助手

本文介绍了我如何在zend中添加视图助手的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  1. 我将以下代码放在application.ini中:
  1. I placed in application.ini this code:

  • 在库目录中创建视图帮助器TabEntry.php

  • create view helper TabEntry.php in library directory

  • 在库目录中创建另一个视图帮助器TabEntries.php

  • create another view helper TabEntries.php in library directory

  • 在我的phtml中使用$ this-> TabEntries()时出错
  • 在Bootstrap.php中,我添加一些代码:
    $ view-> addHelperPath('MyView/Helpers',"library_MyView_Helpers");
    $ viewRenderer = Zend_Controller_Action_HelperBroker :: getStaticHelper('ViewRenderer');$ viewRenderer-> setView($ view);
  • when in my phtml use $this->TabEntries() get error
  • in Bootstrap.php I add some code:
    $view->addHelperPath('MyView/Helpers', "library_MyView_Helpers");
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('ViewRenderer');$viewRenderer->setView($view);
  • 推荐答案

    根据ZF编码应用程序结构,正确的版本应为:

    According to ZF coding application structure, correct version would be:

    在application.ini中:

    In application.ini:

    resources.view.helperPath.Your_View_Helper = "Your/View/Helper"
    

    然后是助手:(不确定为什么需要另一个抽象类):

    Then the helpers: (not sure why do you need another abstract class):

    // library/Your/View/Helper/TabEntry/Abstract.php
    
    class Your_View_Helper_TabEntry_Abstract extends Zend_View_Helper_Abstract {
        public function tabEntry($param1, $param2) {} // note the lower case here
    }
    
    // library/Your/View/Helper/TabEntries.php
    
    class Your_View_Helper_TabEntries extends Your_View_Helper_TabEntry_Abstract {
        public function tabEntries($param1, $param2) {...} // note the lower case
    }
    

    在视图中:

    $this->tabEntries();
    

    重要提示:call_user_func和Linux文件系统区分大小写.

    Important: call_user_func and Linux filesystem are case sensitive.

    这篇关于我如何在zend中添加视图助手的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

    08-15 08:26