doulao3905 2015-01-02 21:29
浏览 24
已采纳

ZEND:无法注册视图助手

I've spend all day an I cannot get it working.

I have this custom view helper class:

class ShowPopupMessages extends Zend_View_Helper_Abstract {

 public function showPopupMessages()
{

 $flashMessenger = Zend_Controller_Action_HelperBroker::getStaticHelper('FlashMessenger');

    if($flashMessenger->hasMessages()) {

        $msg =$flashMessenger->getMessages()[0];

        return "ShowToastMessage('$msg','success')";
    }


}

}

I attach the image of file structure of my project

tree

I'm trying to register this class in my Bootstrap.php:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    protected function _initPlaceholders()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->doctype('XHTML1_STRICT');


        $view->addHelperPath(
            APPLICATION_PATH.'/views/helpers/', 'ShowPopupMessages'
        );
        $helper = new ShowPopupMessages();
        $view->registerHelper($helper, 'showPopupMessages');
}

This is my application.ini:

[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0

resources.view.doctype = "XHTML1_STRICT"
resources.view.helperPath = APPLICATION_PATH "/views/helpers"

but I keep getting:

Fatal error: Class 'ShowPopupMessages' not found in C:\xampp\htdocs\Platforma\application\Bootstrap.php on line 19

Is the class name wrong? Placement in the tree? Can I make it autoload somehow (writing so much code to register each helper is a madness!)? If so, where to put it in the project tree?

Sorry but Zend docs are so proorly written, I just can't learn from them.

Thanks and regards!

Tom

  • 写回答

2条回答 默认 最新

  • dongqian9567 2015-01-04 22:35
    关注

    Following your hints I finally got it:

    May class name is

    class My_View_Helper_ShowPopupMessages extends Zend_View_Helper_Abstract
    

    the helper filename is:

    ShowPopupMessages.php

    and it's placed in \views\helpers

    in bootstrap.php I added:

        protected function _initViewHelperPaths()
    {
        $this->bootstrap('view');
        $view = $this->getResource('view');
        $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'My_View_Helper_');
    }
    

    and no explicit registration of each custom helper is needed as:

    $view->addHelperPath(APPLICATION_PATH . '/views/helpers', 'My_View_Helper_');
    

    does all the job and no further messing with application.ini is required (at least in my simple application)

    thanks and regards

    Tom

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘