本文整理汇总了PHP中yii\web\Request::getBaseUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getBaseUrl方法的具体用法?PHP Request::getBaseUrl怎么用?PHP Request::getBaseUrl使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类yii\web\Request
的用法示例。
在下文中一共展示了Request::getBaseUrl方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRedirectRequest
/**
* @param \yii\web\Request $request
* @return \yii\web\Response|null
*/
protected function handleRedirectRequest($request)
{
$key = ltrim(str_replace($request->getBaseUrl(), '', $request->getUrl()), '/');
if (array_key_exists($key, $this->redirectRoutes)) {
return $this->getResponse()->redirect(Url::to($this->redirectRoutes[$key]));
} else {
return null;
}
}
示例2: redirectToLanguage
/**
* Redirect to the current URL with given language code applied
*
* @param string $language the language code to add. Can also be empty to not add any language code.
*/
protected function redirectToLanguage($language)
{
// Examples:
// 1) /baseurl/index.php/some/page?q=foo
// 2) /baseurl/some/page?q=foo
// 3)
// 4) /some/page?q=foo
if ($this->showScriptName) {
// 1) /baseurl/index.php
// 2) /baseurl/index.php
// 3) /index.php
// 4) /index.php
$redirectUrl = $this->_request->getScriptUrl();
} else {
// 1) /baseurl
// 2) /baseurl
// 3)
// 4)
$redirectUrl = $this->_request->getBaseUrl();
}
if ($language) {
$redirectUrl .= '/' . $language;
}
// 1) some/page
// 2) some/page
// 3)
// 4) some/page
$pathInfo = $this->_request->getPathInfo();
if ($pathInfo) {
$redirectUrl .= '/' . $pathInfo;
}
if ($redirectUrl === '') {
$redirectUrl = '/';
}
// 1) q=foo
// 2) q=foo
// 3)
// 4) q=foo
$queryString = $this->_request->getQueryString();
if ($queryString) {
$redirectUrl .= '?' . $queryString;
}
Yii::$app->getResponse()->redirect($redirectUrl);
if (YII_ENV_TEST) {
throw new \yii\base\Exception(\yii\helpers\Url::to($redirectUrl));
} else {
Yii::$app->end();
}
}
示例3: getBaseUrl
public function getBaseUrl()
{
return str_replace($this->web, "", parent::getBaseUrl()) . $this->adminUrl;
}
示例4: Request
<?php
use yii\web\Request;
$params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
// Replace url
$request = new Request();
$baseUrlFront = str_replace('/admin', '', $request->getBaseUrl());
$scriptUrlFront = str_replace('/admin', '', $request->getScriptUrl());
return ['id' => 'app-backend', 'basePath' => dirname(__DIR__), 'controllerNamespace' => 'backend\\controllers', 'bootstrap' => ['log', 'common\\components\\BackendBootstrap'], 'modules' => [], 'components' => ['user' => ['identityClass' => 'common\\models\\User', 'enableAutoLogin' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'errorHandler' => ['errorAction' => 'site/error'], 'i18n' => ['translations' => ['writesdown' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en', 'fileMap' => []]]], 'urlManagerFront' => ['class' => 'yii\\web\\urlManager', 'scriptUrl' => $scriptUrlFront, 'baseUrl' => $baseUrlFront], 'urlManagerBack' => ['class' => 'yii\\web\\urlManager'], 'authManager' => ['class' => 'yii\\rbac\\DbManager']], 'params' => $params];
示例5: Request
<?php
use yii\web\Request;
$params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
// Replace url
$request = new Request();
$baseUrlBack = str_replace('/frontend/web', '/backend/web', $request->getBaseUrl());
$scriptUrlBack = str_replace('/frontend/web', '/backend/web', $request->getScriptUrl());
return ['id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log'], 'controllerNamespace' => 'frontend\\controllers', 'components' => ['user' => ['identityClass' => 'common\\models\\User', 'enableAutoLogin' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'errorHandler' => ['errorAction' => 'site/error'], 'i18n' => ['translations' => ['writesdown' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en', 'fileMap' => []]]], 'urlManagerFront' => ['class' => 'yii\\web\\urlManager'], 'urlManagerBack' => ['class' => 'yii\\web\\urlManager', 'scriptUrl' => $scriptUrlBack, 'baseUrl' => $baseUrlBack], 'authManager' => ['class' => 'yii\\rbac\\DbManager']], 'params' => $params];
示例6: Request
<?php
use yii\web\Request;
$params = array_merge(require __DIR__ . '/../../common/config/params.php', require __DIR__ . '/../../common/config/params-local.php', require __DIR__ . '/params.php', require __DIR__ . '/params-local.php');
// Replace url
$request = new Request();
$baseUrlBack = $request->getBaseUrl() . '/admin';
$scriptUrlBack = str_replace('/index.php', '/admin/index.php', $request->getScriptUrl());
return ['id' => 'app-frontend', 'basePath' => dirname(__DIR__), 'bootstrap' => ['log', 'common\\components\\FrontendBootstrap'], 'controllerNamespace' => 'frontend\\controllers', 'modules' => [], 'components' => ['user' => ['identityClass' => 'common\\models\\User', 'enableAutoLogin' => true], 'log' => ['traceLevel' => YII_DEBUG ? 3 : 0, 'targets' => [['class' => 'yii\\log\\FileTarget', 'levels' => ['error', 'warning']]]], 'errorHandler' => ['errorAction' => 'site/error'], 'i18n' => ['translations' => ['writesdown' => ['class' => 'yii\\i18n\\PhpMessageSource', 'basePath' => '@app/messages', 'sourceLanguage' => 'en', 'fileMap' => []]]], 'urlManagerFront' => ['class' => 'yii\\web\\urlManager'], 'urlManagerBack' => ['class' => 'yii\\web\\urlManager', 'scriptUrl' => $scriptUrlBack, 'baseUrl' => $baseUrlBack], 'authManager' => ['class' => 'yii\\rbac\\DbManager'], 'view' => ['theme' => []]], 'params' => $params];