视图/助手中的子文件夹

时间:2012-07-05 13:53:52

标签: zend-framework view view-helpers

我想在我的视图/助手中创建不同的文件夹,并在其中添加我的视图助手类。但是我无法访问这些课程。

这样做的最佳方式是什么?

我尝试调整我的application.ini文件设置......但没有运气

这是我在ini文件中设置的内容:

resources.view.helperPath = APPLICATION_PATH "/views/helpers/models"
resources.view.helperPath = APPLICATION_PATH "/views/helpers/test"

modelstest是我/views/helpers文件夹中的子文件夹

有人能提出更好的解决方案吗?

3 个答案:

答案 0 :(得分:1)

使用application.ini中的当前设置,您只需为Zend(Zend_View_Helper_)添加默认视图助手的其他路径。

您必须指定要使用的类前缀:

; View_Helper_Models is the class prefix
resources.view.helperPath.View_Helper_Models = APPLICATION_PATH "/views/helpers/models"
; View_Helper_Test is the class prefix
resources.view.helperPath.View_Helper_Test = APPLICATION_PATH "/views/helpers/test"

现在应用程序知道如何将类名映射到路径。另外,您可以在主Bootstrap.php中启用此功能:

protected function _initViewHelper()
{
   $this->bootstrap( 'view' );
   $this->_view = $this->getResource( 'view' );

   $this->_view->addHelperPath( APPLICATION_PATH . '/views/helpers/models',
                                'View_Helper_Models' );
   $this->_view->addHelperPath( APPLICATION_PATH . '/views/helpers/test',
                                'View_Helper_Test' );
}

注意:路径必须是正确的。

答案 1 :(得分:0)

在配置文件中添加这两行第二行是帮助者的自定义路径

resources.view[] =    
resources.view.helperPath.Zend_View_Helper = APPLICATION_PATH "/../library/FolderA/FolderB/helpers"

创建帮助器时,请给出类似这样的类名称

<?php
class Zend_View_Helper_Foo extends Zend_View_Helper_Abstract
{
   public function foo(){
       echo 'hello world';
   }
}

并将您的任何视图文件中的帮助程序称为$this->foo();

答案 2 :(得分:-1)

我认为您只需要输入正确的视图辅助类名称! 例如,在APPLICATION_PATH“/ views / helpers / models”中创建一个文件“Mine.php”,然后将该类命名为class View_Helper_Models_Mine

希望得到这个帮助。

此致 艾哈迈德B。

相关问题