ZF には、コントローラにフォワード プラグインがあります。マニュアルにはそれについて次のように書かれています。
場合によっては、一致したコントローラー内から追加のコントローラーをディスパッチしたい場合があります。たとえば、このアプローチを使用して、「ウィジェット化された」コンテンツを構築できます。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
ですか?