Sharing Zend Helpers (view or action) Between modules

Assuming you're trying to keep yourself as close as possible to the Zend Framework’s presentation of the universe, how should you share the same module from the same module?

Say I have two modules. Module "A" has a view helper named Output.

class Modulea_Zend_View_Helper_Ouput extends Zend_View_Helper_Abstract
{
    function output($var)
    {
        echo strip_tags($var);
        return true;
    }
}

If I try to use this helper from the view in module "B"

File: moduleb/views/scripts/index/index.phtml

<?php $this->output($somevar); ?>

I get an exception

A plugin named "Exit" was not found in the registry

Which "right" should the auxiliary view element from module B have to use

+3
source share
7 answers

Chillini, Starx:

$view - undefined, Bootstrap:

protected function _initView()
{
    // Initialize view
    $view         = new Zend_View();
    $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
        'ViewRenderer'
    );
    $viewRenderer->setView($view);
    $view->addHelperPath(
        APPLICATION_PATH . '/views/helpers/',
        'My_View_Helper'
    );
}

, , class Modulea_Zend_View_Helper_Ouput class Modulea_Zend_View_Helper_Output .

+2

$this->bootstrap('view');
$view->addHelperPath(APPLICATION_PATH . '/views/helpers/','My_View_Helper');
+1

:

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

..

+1

:

  • : Helpers Library
  • , Output.php
  • "Output.php" :
 class Helpers_Output extends Zend_View_Helper_Abstract
 {      public function ($var)
     {
      echo strip_tags($var);
      return true;
     }
 }

Application.ini

resources.view.helperPath.Helpers = "/"

, , , , , , - Application.ini

+1

:

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {
    public function __construct($application) {
        parent::__construct($application);
        $this->bootstrap("view");
        $view = $this->getResource('view');
        Zend_Registry::set("Zend_View", $view);
    }
}

class Core_Bootstrap extends Zend_Application_Module_Bootstrap {
    public function __construct($application) {
        parent::__construct($application);
        $view = Zend_Registry::get("Zend_View");
        $view->addHelperPath(APPLICATION_PATH . "/modules/core/views/helpers", 'Core_View_Helper');
    }
}

( "" ) , , . (.. ), .

- , , .

+1

. .

:

-application
  --modules
   ---modulea
   ---moduleb
-library
  --view
   ---HELPER

include, set_include_path.

0

, .

library
   Zend
     View
       Helper
         YourHelper.php
   Zend
     Controller
       Action
         Helper
           YourHelper.php

Zend , , . application.ini:

resources.view.helperPath.Application_View_Helper = "Application/View/Helper"
resources.frontController.actionHelperPaths.Application_Controller_Action_Helper = "Application/Controller/Action/Helper"
0

Source: https://habr.com/ru/post/1765529/


All Articles