getScriptUrl() public method

The implementation of this method referenced Zend_Controller_Request_Http in Zend Framework.
public getScriptUrl ( ) : string
return string the relative URL of the entry script.
 /**
  * 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();
     }
 }
Example #2
0
<?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];
Example #3
0
<?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];
Example #4
0
<?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];