redirect() публичный метод

This method is a shortcut to [[Response::redirect()]]. You can use it in an action by returning the Response directly: php stop executing this action and redirect to login page return $this->redirect(['login']);
public redirect ( string | array $url, integer $statusCode = 302 ) : Response
$url string | array the URL to be redirected to. This can be in one of the following formats: - a string representing a URL (e.g. "http://example.com") - a string representing a URL alias (e.g. "@example.com") - an array in the format of `[$route, ...name-value pairs...]` (e.g. `['site/index', 'ref' => 1]`) [[Url::to()]] will be used to convert the array into a URL. Any relative URL will be converted into an absolute one by prepending it with the host info of the current request.
$statusCode integer the HTTP status code. Defaults to 302. See for details about HTTP status code
Результат Response the current response object
 /**
  * @param $flag
  * @param $successMessage
  * @param $failedMessage
  *
  * @return \yii\web\Response
  */
 protected function redirectWithMessages($flag, $successMessage, $failedMessage)
 {
     if ($flag) {
         Yii::$app->session->setFlash('success', $successMessage);
         return $this->controller->redirect($this->successUrl);
     } else {
         Yii::$app->session->setFlash('warning', $failedMessage);
         return $this->controller->redirect($this->failedUrl);
     }
 }
Пример #2
3
 /**
  * @param \yii\base\Action $action
  */
 public function beforeAction($action)
 {
     if ($action->controller->id == 'default') {
         \yii\web\Controller::redirect('/staff/admin');
     }
     return true;
 }
Пример #3
0
 public function redirect($url, $statusCode = 302, $halt = true)
 {
     parent::redirect($url, $statusCode);
     if ($halt) {
         \Yii::$app->end($statusCode);
     }
 }
Пример #4
0
 public function redirect($url, $force = false, $statusCode = 302)
 {
     $params = Yii::$app->request->queryParams;
     // Meta redirect
     if (headers_sent() || ob_get_contents()) {
         $url = !empty($params['_return_url']) ? $params['_return_url'] : $url;
         $url = Url::to($url);
         $this->ech(Html::tag('meta', '', ['http-equiv' => 'Refresh', 'content' => '1;URL=' . $url . '']));
         $this->ech(Html::a(__('Continue'), $url));
     }
     if (!empty($params['_return_url']) && !$force) {
         return Yii::$app->getResponse()->redirect($params['_return_url'], $statusCode);
     }
     return parent::redirect($url, $statusCode);
 }
 /**
  * Dispatch the current controller to the getTransactionGatewayCreat link.
  *
  * @param \yii\web\Controller $controller The Yii controller object.
  * @throws Exception
  */
 public function dispatch(Controller $controller)
 {
     if (!$this->model) {
         throw new PaymentException("Could not dispatch the controller to the requested url as the model object is empty or contains an error.");
     }
     $controller->redirect($this->getTransactionGatewayCreateLink());
 }
Пример #6
0
 /**
  * Redirects and ends app. That prevents from sending additional headers.
  * @inheritdoc
  */
 public function redirect($url, $statusCode = 302)
 {
     parent::redirect($url, $statusCode);
     Yii::$app->end();
 }
Пример #7
0
 public function goHome()
 {
     parent::redirect($this->homePage);
 }