How to add a view helper directory (zend framework)

后端 未结 5 1785
忘掉有多难
忘掉有多难 2020-12-03 16:59

I begin with ZF (1.9.7), and I want to use View Helpers from a library shared between all my projects. But I can\'t find how to add it directory to the helpers path. My herp

5条回答
  •  不思量自难忘°
    2020-12-03 17:38

    There is a problem when using

    resources.view.helperPath.App_View_Helper = APPLICATION_PATH "/../library/App/views/helpers"
    

    I can access no view helper in the layout even local helpers in the module. (Plugin by name 'LoggedInAs' was not found in the registry) but still working in views template files.

    I put this code "echo Zend_Debug::dump($this)" at the end of layout file and there is a part of output.

            ["_prefixToPaths:protected"] => array(3) {
              ["Zend_View_Helper_"] => array(2) {
                [0] => string(17) "Zend/View/Helper/"
                [1] => string(16) "./views\helpers/"
              }
              ["ZendX_JQuery_View_Helper_"] => array(1) {
                [0] => string(25) "ZendX/JQuery/View/Helper/"
              }
              ["Zend_View_Helper_Navigation_"] => array(1) {
                [0] => string(28) "Zend/View/Helper/Navigation/"
              }
            }
    

    but when using these code in the bootstrap file there is no problem.

        //Initialize and/or retrieve a ViewRenderer object on demand via the helper broker
        $viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
        $viewRenderer->initView();
        //add the global helper directory path
        $viewRenderer->view->addHelperPath(APPLICATION_PATH.'/../library/App/views/helpers', 'App_View_Helper');
    

    the output was like below:

                ["_prefixToPaths:protected"] => array(4) {
                  ["Zend_View_Helper_"] => array(3) {
                    [0] => string(17) "Zend/View/Helper/"
                    [1] => string(16) "./views\helpers/"
                    [2] => string(86) "D:/zf/application/modules/default/views\helpers/"
                  }
                  ["App_View_Helper_"] => array(1) {
                    [0] => string(85) "D:\zf\application/../library/App/views/helpers/"
                  }
                  ["ZendX_JQuery_View_Helper_"] => array(1) {
                    [0] => string(25) "ZendX/JQuery/View/Helper/"
                  }
                  ["Zend_View_Helper_Navigation_"] => array(1) {
                    [0] => string(28) "Zend/View/Helper/Navigation/"
                  }
                }
    

提交回复
热议问题