当前位置: 首页>>代码示例>>PHP>>正文


PHP Request::getPathInfo方法代码示例

本文整理汇总了PHP中yii\web\Request::getPathInfo方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::getPathInfo方法的具体用法?PHP Request::getPathInfo怎么用?PHP Request::getPathInfo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\web\Request的用法示例。


在下文中一共展示了Request::getPathInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parseRequest

 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     foreach ($this->skip as $item) {
         if (strpos($request->getPathInfo(), $item) !== false) {
             return false;
         }
     }
     $path = $request->getPathInfo();
     $redirect = false;
     // Слэш в конце
     if (substr($path, -1) == '/') {
         $redirect = true;
         $path = trim($path, '/');
     }
     // Двойной слэш
     if (strpos($path, '//') !== false) {
         $redirect = true;
         $path = str_replace('//', '/', $path);
     }
     // Символы в верхнем регистре
     if (($tmpUrl = strtolower($path)) !== $path) {
         $redirect = true;
         $path = $tmpUrl;
     }
     if ($redirect) {
         Yii::$app->response->redirect([$path], 301);
         Yii::$app->end();
     }
     return false;
 }
开发者ID:voskobovich,项目名称:yii2-seo-toolkit,代码行数:37,代码来源:ClearUrlRule.php

示例2: parseRequest

 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     foreach ($this->skip as $item) {
         if (strpos($request->getPathInfo(), $item) !== false) {
             return false;
         }
     }
     /** @var UrlRoute $model */
     $model = $this->modelClass;
     $model = $model::find()->andWhere(['path' => $request->getPathInfo()])->one();
     if ($model == null) {
         return false;
     }
     if ($model->checkAction($model::ACTION_INDEX)) {
         return [$model->getRoute()];
     } elseif ($model->checkAction($model::ACTION_VIEW)) {
         return [$model->getRoute(), ['id' => $model->object_id]];
     } elseif ($model->checkAction($model::ACTION_REDIRECT)) {
         $url = $model->url_to;
         if (strpos($url, 'http://') === false) {
             $url = [$url];
         }
         Yii::$app->response->redirect($url, $model->http_code);
         Yii::$app->end();
     }
     return false;
 }
开发者ID:voskobovich,项目名称:yii2-seo-toolkit,代码行数:34,代码来源:UrlRule.php

示例3: parseRequest

 /**
  * Parses the given request and returns the corresponding route and parameters.
  *
  * @param UrlManager $manager the URL manager
  * @param Request    $request the request component
  *
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     echo '<pre>==== BeeUrlRule ===<br>';
     print_r('PathInfo = ' . $request->getPathInfo());
     echo '<br>';
     print_r('Url = ' . $request->getUrl());
     echo '<br>======================</pre>';
     $items = Yii::$app->getSiteMenu()->getMenu();
     // Parse SEF URL
     if (Yii::$app->urlManager->enablePrettyUrl == TRUE) {
         $route = $request->getPathInfo();
         /*
          *  Пошаговый парсинг меню
          *  Последне найденный записывается в переменную $found
          */
         $found = null;
         foreach ($items as $item) {
             if ($item->path && BeeString::strpos($route, $item->path) === 0) {
                 // Exact route match. We can break iteration because exact item was found.
                 if ($item->path == $route) {
                     $found = $item;
                     break;
                 }
                 // Partial route match. Item with highest level takes priority.
                 if (!$found || $found->level < $item->level) {
                     $found = $item;
                 }
             }
         }
         /*
          * Если мы нашли конечный пункт меню и его адрес полностью собпадает,
          * то формируем и возвращаем ссылку на этот пункт меню
          * иначе берем компонент в @found и продолжаем поиск уже по этому компоненту.
          */
         if (BeeString::strpos($route, $found->path) === 0) {
             $extAction = $found->query[0];
             // site/index
             $url = ['path' => $found->query['path'], 'id' => $found->query['id']];
             return [$extAction, $url];
         } else {
             echo '<pre>';
             print_r('------------------- Еще не все распарсил -------------------');
             echo '</pre>';
         }
         //echo '<br><br><br><pre>';
         //print_r($found);
         //echo '</pre><br><br><br>';
         echo '<br><pre>Сделать парсинг для страниц, отсутствующих в меню';
         echo '<br>======================</pre>';
     } else {
         // Parse RAW URL
         return FALSE;
     }
     echo '<pre><<< Стандартный парсино Yii >>></pre>';
     return FALSE;
     //return ['site/about', []];
 }
开发者ID:Sywooch,项目名称:Bee-CMS,代码行数:66,代码来源:BeeUrlRule.php

示例4: parseRequest

 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     if ($this->mode === self::CREATION_ONLY) {
         return false;
     }
     if (!empty($this->verb) && !in_array($request->getMethod(), $this->verb, true)) {
         return false;
     }
     $pathInfo = $request->getPathInfo();
     if ($this->host !== null) {
         $pathInfo = strtolower($request->getHostInfo()) . ($pathInfo === '' ? '' : '/' . $pathInfo);
     }
     $params = $request->getQueryParams();
     $suffix = (string) ($this->suffix === null ? $manager->suffix : $this->suffix);
     $treeNode = null;
     $originalDir = $pathInfo;
     if ($suffix) {
         $originalDir = substr($pathInfo, 0, strlen($pathInfo) - strlen($suffix));
     }
     $dependency = new TagDependency(['tags' => [(new Tree())->getTableCacheTag()]]);
     if (!$pathInfo) {
         $treeNode = Tree::getDb()->cache(function ($db) {
             return Tree::find()->where(["site_code" => \Yii::$app->cms->site->code, "level" => 0])->one();
         }, null, $dependency);
     } else {
         $treeNode = Tree::find()->where(["dir" => $originalDir, "site_code" => \Yii::$app->cms->site->code])->one();
     }
     if ($treeNode) {
         \Yii::$app->cms->setCurrentTree($treeNode);
         $params['id'] = $treeNode->id;
         return ['cms/tree/view', $params];
     } else {
         return false;
     }
 }
开发者ID:skeeks-cms,项目名称:cms,代码行数:40,代码来源:UrlRuleTree.php

示例5: getFormat

 /**
  * 获取响应的格式
  * @return string
  */
 protected function getFormat()
 {
     if ('' != ($extension = pathinfo($this->request->getPathInfo(), PATHINFO_EXTENSION))) {
         $this->format = strtolower($extension);
     }
     return $this->format == '' ? 'html' : $this->format;
 }
开发者ID:heartshare,项目名称:yii2-liuxy-extension,代码行数:11,代码来源:WebController.php

示例6: parseRequest

 /**
  * Parses the URL and sets the language accordingly
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($request)
 {
     if ($this->enablePrettyUrl) {
         $pathInfo = $request->getPathInfo();
         $language = explode('/', $pathInfo)[0];
         $locale = ArrayHelper::getValue($this->aliases, $language, $language);
         if (in_array($language, $this->languages)) {
             $request->setPathInfo(substr_replace($pathInfo, '', 0, strlen($language) + 1));
             Yii::$app->language = $locale;
             static::$currentLanguage = $language;
         }
     } else {
         $params = $request->getQueryParams();
         $route = isset($params[$this->routeParam]) ? $params[$this->routeParam] : '';
         if (is_array($route)) {
             $route = '';
         }
         $language = explode('/', $route)[0];
         $locale = ArrayHelper::getValue($this->aliases, $language, $language);
         if (in_array($language, $this->languages)) {
             $route = substr_replace($route, '', 0, strlen($language) + 1);
             $params[$this->routeParam] = $route;
             $request->setQueryParams($params);
             Yii::$app->language = $locale;
             static::$currentLanguage = $language;
         }
     }
     return parent::parseRequest($request);
 }
开发者ID:loveorigami,项目名称:yii2-i18n-url,代码行数:34,代码来源:I18nUrlManager.php

示例7: parseRequest

 /**
  *
  * @param \yii\web\UrlManager $manager            
  * @param \yii\web\Request $request            
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $rule = $this->getRuleByPattern($request->getPathInfo(), null);
     if ($rule) {
         $params = [];
         parse_str($rule->defaults, $params);
         return [$rule->route, $params];
     }
     return false;
 }
开发者ID:rocketyang,项目名称:hasscms-app,代码行数:16,代码来源:UrlRule.php

示例8: getPathInfo

 public function getPathInfo()
 {
     // Добавить кэш $pathInfo (не забыть про setPathInfo)
     $pathInfo = parent::getPathInfo();
     $pattern = Languages::all()->pattern();
     if (preg_match("/^({$pattern})\\/(.*)/", $pathInfo, $arr)) {
         $this->lang_url = $arr[1];
         $pathInfo = $arr[count($arr) - 1];
     }
     return $pathInfo;
 }
开发者ID:alisherdavronov,项目名称:yii2-multilanguage,代码行数:11,代码来源:AdvancedRequest.php

示例9: getRouteFromSlug

 /**
  * @param \yii\web\Request $request
  * @return string
  */
 public function getRouteFromSlug($request)
 {
     $_route = $request->getPathInfo();
     $_params = $request->get();
     $dbRoute = $this->getRouteFromCacheOrWriteCacheThenRead($_route, $_params);
     if (is_object($dbRoute) && $dbRoute->hasAttribute('redirect')) {
         if ($dbRoute->getAttribute('redirect')) {
             Yii::$app->response->redirect([$dbRoute->slug], $dbRoute->getAttribute('redirect_code'));
         }
     }
     return $_route;
 }
开发者ID:fg,项目名称:yii2-url-alias,代码行数:16,代码来源:UrlRule.php

示例10: parseRequest

 /**
  * Parse request
  *
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  *
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $url = preg_replace('#/$#', '', $pathInfo);
     $page = (new CmsModel())->findPage($url);
     if (!empty($page)) {
         $params['pageAlias'] = $url;
         $params['pageId'] = $page->id;
         return [$this->route, $params];
     }
     return parent::parseRequest($manager, $request);
 }
开发者ID:yii2mod,项目名称:yii2-cms,代码行数:20,代码来源:PageUrlRule.php

示例11: parseRequest

 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param UrlManager $manager the URL manager
  * @param Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     // If it's base url - call main page
     if ($request->getPathInfo() === '') {
         $mainPage = $this->getMainPage();
         if ($mainPage !== false) {
             Singleton::setData('content_template_id', $mainPage['content_template_id']);
             if ($mainPage['type'] == ContentPage::TYPE_TEXT) {
                 return ['/content/default/view', ['slug' => $mainPage['slug']]];
             } elseif ($mainPage['type'] == ContentPage::TYPE_INTERNAL_LINK) {
                 return ['/' . ltrim($mainPage['slug'], '/'), []];
             }
         }
     }
     $path = rtrim($request->getPathInfo(), '/');
     $parts = explode('/', $path);
     $languagePart = null;
     // Multilingual support - remove language from parts
     if (isset(Yii::$app->params['mlConfig']['languages'])) {
         if (array_key_exists($parts[0], Yii::$app->params['mlConfig']['languages'])) {
             $languagePart = array_shift($parts);
         }
     }
     $slug = count($parts) == 1 && $parts[0] != '' ? $parts[0] : end($parts);
     if (isset($this->getAllPages()[$slug])) {
         if (isset($this->getAllPages()[$slug])) {
             $page = $this->getAllPages()[$slug];
             Singleton::setData('content_template_id', $page['content_template_id']);
             return ['content/default/view', ['slug' => $slug, '_language' => $languagePart]];
         }
     } elseif (count($parts) > 1) {
         $slug = implode('/', $parts);
         if (isset($this->getAllPages()[$slug])) {
             $page = $this->getAllPages()[$slug];
             Singleton::setData('content_template_id', $page['content_template_id']);
         }
     }
     return false;
     // this rule does not apply
 }
开发者ID:webvimark,项目名称:ybc-content,代码行数:47,代码来源:ContentUrlRule.php

示例12: parseRequest

 /**
  * Parses the given request and returns the corresponding route and parameters.
  * @param \yii\web\UrlManager $manager the URL manager
  * @param \yii\web\Request $request the request component
  * @return array|boolean the parsing result. The route and the parameters are returned as an array.
  * If false, it means this rule cannot be used to parse this path info.
  */
 public function parseRequest($manager, $request)
 {
     $this->initPatrones();
     $pathInfo = $request->getPathInfo();
     //vendedor
     if ($this->verificaRuta($this->patrones[self::P_VENDEDOR], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_VENDEDOR], $pathInfo);
         return [$this->ruta[self::P_VENDEDOR], $parametros];
     }
     //profesional
     if ($this->verificaRuta($this->patrones[self::P_PROFESIONAL], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_PROFESIONAL], $pathInfo);
         return [$this->ruta[self::P_PROFESIONAL], $parametros];
     }
     //categoria
     if ($this->verificaRuta($this->patrones[self::P_CATEGORIAS], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIAS], $pathInfo);
         //            echo '<pre>';print_r([__LINE__, __METHOD__,$pathInfo,$this->patrones[self::P_CATEGORIAS]]);die();
         //registrar click
         //            if(Yii::$app->request->getBodyParam('hc') == 7 ){
         //                Yii::$app->visitas->registrarClick($parametros['categoria'], 'C');
         //            }
         //registro de impresion de la categoria
         //            Yii::$app->visitas->registrarImpresion($parametros['categoria'], 'C');
         return [$this->ruta[self::P_CATEGORIAS], $parametros];
     }
     //categoria-provincia
     if ($this->verificaRuta($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_CATEGORIA_PROVINCIA], $pathInfo);
         //registro de impresion de la categoria
         return [$this->ruta[self::P_CATEGORIA_PROVINCIA], $parametros];
     }
     //detalle articulo
     //municipio/articulo
     if ($this->verificaRuta($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_MUNICIPIO_DESCUENTO], $pathInfo);
         //registrar click
         //            if(Yii::$app->request->getBodyParam('hc') == 7 ){
         //                Yii::$app->visitas->registrarClick($parametros['articulo'], 'A');
         //            }
         //registro de impresion de la categoria
         //            Yii::$app->visitas->registrarImpresion($parametros['articulo'], 'A');
         return [$this->ruta[self::P_MUNICIPIO_DESCUENTO], $parametros];
     }
     //provincia
     if ($this->verificaRuta($this->patrones[self::P_PROVINCIA], $pathInfo)) {
         $parametros = $this->obtenerParametros($this->patrones[self::P_PROVINCIA], $pathInfo);
         return [$this->ruta[self::P_PROVINCIA], $parametros];
     }
     return false;
 }
开发者ID:alejandrososa,项目名称:AB,代码行数:58,代码来源:DescuentosUrlRules.php

示例13: parseRequest

 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (!in_array(StringHelper::strtolower($extension), (array) \Yii::$app->imaging->extensions)) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
开发者ID:skeeks-cms,项目名称:cms,代码行数:19,代码来源:ImagingUrlRule.php

示例14: parseRequest

 /**
  * @param \yii\web\UrlManager $manager
  * @param \yii\web\Request $request
  * @return array|bool
  */
 public function parseRequest($manager, $request)
 {
     $pathInfo = $request->getPathInfo();
     $params = $request->getQueryParams();
     $sourceOriginalFile = File::object($pathInfo);
     $extension = $sourceOriginalFile->getExtension();
     if (!$extension) {
         return false;
     }
     if (Validate::validate(new AllowExtension(), $extension)->isInvalid()) {
         return false;
     }
     return ['cms/imaging/process', $params];
 }
开发者ID:Liv1020,项目名称:cms,代码行数:19,代码来源:ImagingUrlRule.php

示例15: 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();
     }
 }
开发者ID:JQL,项目名称:Yii2_Basic_Configuration,代码行数:54,代码来源:UrlManager.php


注:本文中的yii\web\Request::getPathInfo方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。