2016-10-19 8 views
0

, 나는 마법의 방법을 추가 할 필요가 __invoke보기 도우미에서 방법; 그렇지 않으면 Twig 템플릿 엔진이 __invoke 뷰 도우미 메서드를 호출 할 수 없다는 오류를 발생시킵니다.왜 사용자 정의보기 도우미를 사용하는 동안 Twig에 __invoke 메서드가 필요합니까? <strong>ZF2</strong> 기반 프로젝트에서 구현하는 동안 나는 <strong>나뭇 가지</strong> 템플릿 내 사용자 정의보기 헬퍼를 사용하려는 경우

이제 이것을 선언해야하는 이유를 알고 싶습니다. __invoke보기 도우미에서 마술 기능을 사용할 수 있습니까?

답변

1

확인 문서 :

당신이 당신의 도우미가, 당신은 또한 당신의 도우미 내 __invoke() 메소드를 구현해야 PhpRenderer의 메서드 호출 인 것처럼 호출 할 수 있어야합니다 https://framework.zend.com/manual/2.1/en/modules/zend.view.helpers.advanced-usage.html.

나뭇 가지 렌더러에 적용해야합니다 같은, (바로 가기로 호출 사용)

당신은 PHPRenderer를 프록시로 __invoke()를 사용하는 경우/참조 도우미에 바로 가기 할 수있는 헬퍼 클래스를 실행하려고

:

https://github.com/zendframework/zend-view/blob/master/src/Renderer/PhpRenderer.php#L389

/** 
* Overloading: proxy to helpers 
* 
* Proxies to the attached plugin manager to retrieve, return, and potentially 
* execute helpers. 
* 
* * If the helper does not define __invoke, it will be returned 
* * If the helper does define __invoke, it will be called as a functor 
* 
* @param string $method 
* @param array $argv 
* @return mixed 
*/ 
public function __call($method, $argv) 
{ 
    $plugin = $this->plugin($method); 
    if (is_callable($plugin)) { 
     return call_user_func_array($plugin, $argv); 
    } 
    return $plugin; 
} 

은 나는 나뭇 가지 렌더러 그냥 비슷한 일을하고 상상 가리키고 그것이 아래 우리는 볼 수 있습니다

,

https://github.com/ZF-Commons/ZfcTwig/blob/master/src/ZfcTwig/View/TwigRenderer.php#L83

+0

좋은 설명에 대해 감사드립니다. –