1

ZF에는 컨트롤러에 Forward Plugin이 있습니다. 설명서는 그것에 대해 말한다 :ZF2 : Forward Controller Plugin을 사용하여 다른 Action 메소드에서 요청을 완료하는 방법은 무엇입니까?

때때로, 당신이 일치하는 컨트롤러 내에서 에서 추가 컨트롤러를 파견 할 수 있습니다 - 예를 들어, 당신은 "에서는 widgetized"컨텐츠를 구축하기 위해 방법을 사용할 수 있습니다. Forward 플러그인을 사용하면 이이를 활성화합니다.

그것의 예는 다음과 같다 :

$foo = $this->forward()->dispatch('foo', array('action' => 'process')); 

플러그인은 플러그인을 호출 초기 일치하는 컨트롤러에 foo 컨트롤러 (FooController::processAction)에서 뭔가를 반환합니다. 하지만 그 foo 컨트롤러에서 요청을 완료 할 수 있습니까 (브라우저에 최종 응답 보내기) 할 수 있습니까? 이와 같이 :

class IndexController extends AbstractActionController { 

    // The request comes here by routes 
    public function indexAction() { 

     if($someCondition) { 

      // I forward the request to the fooAction of this IndexController 
      // And I do not wait for any return from it, the response 
      // will be sent from fooAction, the run will not come back here 
      $this->forward()->dispatch('index', array('action' => 'foo')); 
     } 
    } 

    // I want to send the response from this action and finish with the request 
    public function fooAction() { 

     $response = $this->getResponse(); 
     $response->setStatusCode(200); 
     $response->setContent($someContent); 

     // But it returns the response to the indexAction, 
     // instead of sending it to browser. 
     // How to finish the request here? 
     return $response; 
    } 
} 

Forward은 가능한가요?

답변

3

사용 일반 PHP return 구조 :

return $this->forward()->dispatch('index', array('action' => 'foo'));