0
votes

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
In your Bootstrap.php file I noticed the case different for (s)howPopupMessages when you registerHelper I didn't know if that was intentional. - Demodave
I've checked helpers name convention in my project and we use names like this "Zend_View_Helper_MyCustomHelper", so try "Zend_View_Helper_ShowPopupMessages". I'm pretty sure that helper class name should contain path to actual file. - Tamara

2 Answers

0
votes

Try:

In application.ini

resources.view.helperPath.My_View_Helper = APPLICATION_PATH "/views/helpers"

And class name: My_View_Helper_ShowPopupMessages

0
votes

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