2010-02-25 3 views
19

필자는 ZF (1.9.7)로 시작하고 모든 프로젝트에서 공유되는 라이브러리에서 뷰 도우미를 사용하고 싶습니다. 하지만 헬퍼 경로에 디렉토리를 추가하는 방법을 찾을 수 없습니다. 내 헤퍼는 응용 프로그램의 도우미 경로에 넣을 때 벌금을 부과합니다.뷰 도우미 디렉토리 추가 방법 (젠드 프레임 워크)

다음은 오류입니다. 여기에서 ZF 도우미의 경로와 응용 프로그램 경로를 찾을 수 있습니다.

object(ArrayObject)#71 (3) { 
    ["exception"]=> 
    object(Zend_Loader_PluginLoader_Exception)#70 (6) { 
    ["message:protected"]=> 
    string(151) "Plugin by name 'Voo' was not found in the registry; used paths: 
Zend_View_Helper_: Zend/View/Helper/;C:/ZendStd/www/applis/VOO4_PROJECTX/views\helpers/" 
    ["string:private"]=> 
    string(0) "" 
    ["code:protected"]=> 
    int(0) 
    ["file:protected"]=> 
    string(89) "C:\Program Files\Zend\ZendServer\share\ZendFramework\library\Zend\Loader\PluginLoader.php" 
    ["line:protected"]=> 
    int(401) 

안부
세드릭

답변

38

을 수행 할 수 있습니다 Zend_Application에 ZF 수동 장을 체크 아웃 부트 스트랩 클래스 및 자원을 사용하는 방법을 볼 수 뷰에 내장 된 Zend_Application 리소스. 값을 상주 경로를

resources.view.helperPath.My_View_Helper = "My/View/Helper" 

키의 끝이 클래스 이름 접두사이고, : 당신은 INI CONFIGS를 사용하는 경우, 다음과 같은 라인을 추가합니다.

+0

대단히 저를 구해 주셔서 감사합니다. 5 시간 –

11

도우미 경로는 Zend_View_Abstract::addHelperPath()을 통해 추가됩니다. 이 메소드는 기존 View 인스턴스에서 직접 호출 할 수 있습니다.

도우미 경로는 부트 스트랩 중에 다양한 방법으로 구성 할 수 있습니다. 그것은 아주 쉽게와

+1

은, 내가 느끼는 데이비드가 제시 한'application.ini' 솔루션은 "모범 사례"로 :

//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'); 

출력은 다음과 같았다 . 또한, "_initView()"에서는 $ this-> bootstrap ('view')를 사용할 수 있습니다; 무작위로 생성하는 대신에 application.ini보기를 사용하려면 ... – gnarf

+0

'addHelperPath()'를 제외하고는 @gnarf를 사용하면 부트 스트랩 예제가 복사됩니다. 1 ($ view = $ this-> getResource ('view'); : ZF 참조 가이드의 1. 예를 들어 다른 것으로 받아 들여서는 안됩니다. 다른 방법 (예 : Ini 사용)이 있다는 것을 잘 알고 있습니다. 자유롭게 다르게 할 수 있습니다. – Gordon

1

편집 : 롭 알렌의 Loggedinas보기 도우미를 사용하여이 문제에 대한보다 자세한 걸릴에 대한 view helper in zend framework를 확인하십시오.

David Caunt가 지정한대로 할 수있을뿐만 아니라 부트 스트랩에서 이와 같이 할 수도 있습니다. 당신이보기 개체에 액세스 할 수있는 다음을 수행하는 경우 젠드 프레임 워크에 http://devzone.zend.com/article/3412

확인을 무엇을 할 수있는 하나 개 이상의 방법이 항상 존재합니다.

<?php  
$view->addHelperPath('My/View/Helper/', 'My_View_Helper'); 
?> 

당신이

또한 여기에서 시작 게시물이 정말 좋은 세트를 체크 아웃 프론트 컨트롤러 플러그인에 당신이 경우 뷰 오브젝트를 취득해야 할 수 있습니다

http://zend-framework-community.634137.n4.nabble.com/Getting-view-from-Bootstrap-ZF1-8-tp659447p659460.html

5

가있다 사용시 문제가 발생했습니다.

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

레이아웃에서 엘프 모듈의 로컬 도우미조차도.(이름으로 'LoggedInAs'플러그인을 레지스트리에서 찾을 수 없음) 뷰 템플릿 파일에서 계속 작업하고 있습니다.

나는이 코드를 "echo Zend_Debug :: dump ($ this)"를 레이아웃 파일의 끝에 넣었고 출력 부분이있다.

 ["_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/" 
      } 
     } 

그러나이 코드를 부트 스트랩 파일에 사용하면 문제가 없습니다. 이러한 모든 옵션이 올바른지, 그리고 작동하지만

  ["_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/" 
       } 
      } 
+0

당신의 솔루션은 매력처럼 작동했습니다! 전체 애플리케이션과 도우미를 위해 각 모듈의 헬퍼를 사용했습니다! 이것은 내가 찾고 있었던 것이다! ;) –