2011-05-10 5 views
0

Zend_View를 Zend_Registry에 넣으려고합니다. 그 간단한 작업에 문제가 있습니다. Zend_View는 자원으로 application.ini 초기화합니다 : 그것은 잘 작동리소스로 Zend_View를 Zend_Registry에 넣습니다.

resources.view.encoding = "UTF-8" 
resources.view.contentType = "text/html; charset=UTF-8" 
resources.view.doctype = "HTML4_STRICT" 
resources.view.helperPath.ZendX_JQuery_View_Helper = "ZendX/JQuery/View/Helper" 

, 그때 Bootstrap.php에 방법을 추가하여 레지스트리에 넣고 싶었다.

protected function _initView() 
{ 
    $view = $this->getResource('view'); 
    Zend_Registry::set('view', $view); 

    return $view; 
} 

내가보기 초기화 오류 얻을 새로 고침 후 :

Catchable fatal error: Argument 1 passed to ZendX_JQuery::enableView() must be an instance of Zend_View_Interface, null given, called in D:\projekty\xxx\library\ZendX\Application\Resource\Jquery.php on line 91 and defined in D:\projekty\xxx\library\ZendX\JQuery.php on line 104 

내가 잘못하고있는 중이 야 무엇을? jQuery 오류가 발생하지 않습니다.

+2

왜 뷰 객체를 레지스트리에 넣어야합니까? – Vika

+0

좋은 점 Vika, MVC의 아이디어를 파괴합니다. –

+0

@jake : Zend_View를 사용하여 본문을 렌더링 한 Zend_Mailer를 통해 메일러를 보내고 싶습니다. 이 aproach에 어떤 문제가 있습니까? – Somal

답변

0

리소스를 초기화하는 방법에는 application.ini 파일과 부트 스트랩 클래스에서 _init 메서드를 사용하는 두 가지 방법이 있습니다. 응용 프로그램이 부트 스트랩되면 _init 메소드가 먼저 실행되고 그 다음에 ini 파일 자원이 실행됩니다. 그래서 코드 문제는 $this->getResource('view')이 실행될 때 뷰 자원이 아직 존재하지 않기 때문에 null을 반환합니다. 그런 다음 null을 레지스트리에 두는 것이므로 나중에 오류의 원인이됩니다.

레지스트리에 뷰 객체가 필요한 이유가 명확하지 않으므로 더 나은 접근 방식을 제안 할 수 있다고 설명 할 수 있습니다.

0

_init 메소드를 호출하십시오. 여기에는 이름 충돌이있을 수 있습니다.

protected function _initViewInRegistry() { 
    // run view resource 
    $this->bootstrap('view'); 

    // put view resource in registry 
    Zend_Registry::set('view', $this->getResource('view')); 
} 

이/의미를 이름에 약간의 추한, 그것은 완전히 레지스트리 인스턴스를 설정하는 레지스트리 자원에 더 적합 할 수있다.