1

在 ZF 中,控制器中有一个 Forward Plugin。手册说:

有时,您可能希望从匹配的控制器中调度其他控制器——例如,您可能使用这种方法来构建“小部件化”内容。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 回答