1

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ですか?

4

1 に答える 1

3

通常の phpreturn構成を使用します。

return $this->forward()->dispatch('index', array('action' => 'foo'));
于 2012-11-25T19:17:56.483 に答える