Zend:在哪里/如何注册自定义视图助手? [英] Zend: Where/how can I register custom view helpers?

查看:29
本文介绍了Zend:在哪里/如何注册自定义视图助手?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 layout.phtml 文件中,我有:

In my layout.phtml file I have :

<?php echo $this->Test(); ?>

我在 application/views/helpers/Test.php

<?php 

class My_View_Helper_Test extends Zend_View_Helper_Abstract {

    public function Test() {
        return 'test';
    }

}

还有我的配置文件@configs/application.ini:

resources.view[] = ''
resources.view.helperPath = APPLICATION_PATH "/views/helpers"

我得到的错误:

Zend_Loader_PluginLoader_Exception:未找到名为Test"的插件登记处;使用的路径:Zend_View_Helper_:Zend/View/Helper/:./views/helpers/in/usr/share/php/Zend/Loader/PluginLoader.php在线 406

Zend_Loader_PluginLoader_Exception: Plugin by name 'Test' was not found in the registry; used paths: Zend_View_Helper_: Zend/View/Helper/:./views/helpers/ in /usr/share/php/Zend/Loader/PluginLoader.php on line 406

同样,我也无法注册我的管理员视图助手..

On a similar note I can't register my admin view helper either..

resources.view.helperPath.Admin_View_Helper = APPLICATION_PATH "/modules/admin/views/helpers"

我的modules/admin/views/helpers/AdminPanel.php:

<?php

class My_View_Helper_AdminPanel extends Zend_View_Helper_Abstract {

public function AdminPanel() { return 'test'; }

}

我别无选择,只能在 Bootstrap 中使用 addHelperPath 执行此操作吗?如果是这样,有人可以演示我将如何使用我的路径吗?

Do I have no choice but to do this in the Bootstrap with addHelperPath? If so could someone demonstrate how I would using my paths?

推荐答案

使用 application.ini 可能是定义这些的最佳方式.我把我所有的视图助手放在我的库文件夹中:

Using application.ini is probably the best way to define these. I put all my view helpers inside my library folder:

includePaths.library = APPLICATION_PATH "/../library"
autoloadernamespaces.0 = "SNTrack_"

;  -- Note, these are the only resources.view lines I have...
resources.view.doctype = "XHTML1_STRICT"
resources.view.helperPath.SNTrack_View_Helper = APPLICATION_PATH "/../library/SNTrack/View/Helper"

目录结构:

/
  application/
  library/
    SNTrack/
      View/
        Helper/
          Test.php

查看:

 $this->test('test')

SNTrack/View/Helper/Test.php:

SNTrack/View/Helper/Test.php:

 class SNTrack_View_Helper_Test extends Zend_View_Helper_Abstract {
   public function test($args) { return $args; }
 }

这篇关于Zend:在哪里/如何注册自定义视图助手?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆