1
在ZF中,控制器中有一個正向插件。手冊上說一下:ZF2:如何完成來自其他Action方法的請求,然後請求使用Forward Controller插件?
有時,你可能想匹配的控制器內 派遣額外的控制器 - 例如,你可以使用這個方法 建立「部件化」內容。 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
?