浏览器跳转

操作的方法返回 redirect() 方法的结果,如前所述, 操作的方法返回的响应对象会被当总响应发送给终端用户。

public function actionOld()
{
    return $this->redirect('http://example.com/new', 301);
}

除了动作方法外,可直接调用redirect() 再调用 send() 方法来确保没有其他内容追加到响应中。

\Yii::$app->response->redirect('http://example.com/new', 301)->send();