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 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大