public static home ( boolean | string $scheme = false ) : string | ||
$scheme | boolean | string | the URI scheme to use for the returned URL: - `false` (default): returning a relative URL. - `true`: returning an absolute base URL whose scheme is the same as that in [[\yii\web\UrlManager::$hostInfo]]. - string: returning an absolute URL with the specified scheme (either `http`, `https` or empty string for protocol-relative URL). |
return | string | home URL |
public static function home($scheme = false)
{
$url = Yii::$app->getHomeUrl();
if ($scheme !== false) {
$url = static::getUrlManager()->getHostInfo() . $url;
$url = static::ensureScheme($url, $scheme);
}
return $url;
}
public function actionSet($lang) { if (!Yii::$app->user->isGuest) { Yii::$app->user->identity->scenario = 'language'; Yii::$app->user->identity->lang = $lang; Yii::$app->user->identity->save(); } Yii::$app->session->set('lang', $lang); $redirectUrl = Yii::$app->request->get('redirect', false); if (!$redirectUrl) { $redirectUrl = Yii::$app->request->referrer; } if (!$redirectUrl) { $redirectUrl = \yii\helpers\BaseUrl::home(true); } return $this->redirect($redirectUrl); }