目前还没有内置的支持。它应该很简单,可以自己实现,例如覆盖
Controller::invokeAction()
捕获重定向异常,并使其相应地返回重定向响应,例如:
public function invokeAction()
{
try {
return parent::invokeAction();
} catch (\Cake\Routing\Exception\RedirectException $exception) {
return $this->redirect($exception->getMessage(), $exception->getCode());
}
}
private function initData()
{
if ($this->validData()) {
// ....
} else {
throw new \Cake\Routing\Exception\RedirectException(
\Cake\Routing\Router::url([/* ... */]), // redirect URL
302 // HTTP status code
);
}
}