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


PHP Grav::redirectLangSafe方法代码示例

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


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

示例1: dispatch

 /**
  * Dispatch URI to a page.
  *
  * @param string $url The relative URL of the page
  * @param bool $all
  *
  * @param bool $redirect
  * @return Page|null
  * @throws \Exception
  */
 public function dispatch($url, $all = false, $redirect = true)
 {
     // Fetch page if there's a defined route to it.
     $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null;
     // Try without trailing slash
     if (!$page && Utils::endsWith($url, '/')) {
         $page = isset($this->routes[rtrim($url, '/')]) ? $this->get($this->routes[rtrim($url, '/')]) : null;
     }
     // Are we in the admin? this is important!
     $not_admin = !isset($this->grav['admin']);
     // If the page cannot be reached, look into site wide redirects, routes + wildcards
     if (!$all && $not_admin) {
         // If the page is a simple redirect, just do it.
         if ($redirect && $page && $page->redirect()) {
             $this->grav->redirectLangSafe($page->redirect());
         }
         // fall back and check site based redirects
         if (!$page || $page && !$page->routable()) {
             /** @var Config $config */
             $config = $this->grav['config'];
             // See if route matches one in the site configuration
             $route = $config->get("site.routes.{$url}");
             if ($route) {
                 $page = $this->dispatch($route, $all);
             } else {
                 // Try Regex style redirects
                 $site_redirects = $config->get("site.redirects");
                 if (is_array($site_redirects)) {
                     foreach ((array) $site_redirects as $pattern => $replace) {
                         $pattern = '#' . $pattern . '#';
                         try {
                             $found = preg_replace($pattern, $replace, $url);
                             if ($found != $url) {
                                 $this->grav->redirectLangSafe($found);
                             }
                         } catch (ErrorException $e) {
                             $this->grav['log']->error('site.redirects: ' . $pattern . '-> ' . $e->getMessage());
                         }
                     }
                 }
                 // Try Regex style routes
                 $site_routes = $config->get("site.routes");
                 if (is_array($site_routes)) {
                     foreach ((array) $site_routes as $pattern => $replace) {
                         $pattern = '#' . $pattern . '#';
                         try {
                             $found = preg_replace($pattern, $replace, $url);
                             if ($found != $url) {
                                 $page = $this->dispatch($found, $all);
                             }
                         } catch (ErrorException $e) {
                             $this->grav['log']->error('site.routes: ' . $pattern . '-> ' . $e->getMessage());
                         }
                     }
                 }
             }
         }
     }
     return $page;
 }
开发者ID:indigo423,项目名称:blog.no42.org,代码行数:70,代码来源:Pages.php

示例2: dispatch

 /**
  * Dispatch URI to a page.
  *
  * @param $url
  * @param bool $all
  * @return Page|null
  */
 public function dispatch($url, $all = false)
 {
     // Fetch page if there's a defined route to it.
     $page = isset($this->routes[$url]) ? $this->get($this->routes[$url]) : null;
     // If the page cannot be reached, look into site wide redirects, routes + wildcards
     if (!$all && (!$page || !$page->routable())) {
         /** @var Config $config */
         $config = $this->grav['config'];
         // See if route matches one in the site configuration
         $route = $config->get("site.routes.{$url}");
         if ($route) {
             $page = $this->dispatch($route, $all);
         } else {
             // Try Regex style redirects
             foreach ((array) $config->get("site.redirects") as $pattern => $replace) {
                 $pattern = '#' . $pattern . '#';
                 try {
                     $found = preg_replace($pattern, $replace, $url);
                     if ($found != $url) {
                         $this->grav->redirectLangSafe($found);
                     }
                 } catch (ErrorException $e) {
                     $this->grav['log']->error('site.redirects: ' . $pattern . '-> ' . $e->getMessage());
                 }
             }
             // Try Regex style routes
             foreach ((array) $config->get("site.routes") as $pattern => $replace) {
                 $pattern = '#' . $pattern . '#';
                 try {
                     $found = preg_replace($pattern, $replace, $url);
                     if ($found != $url) {
                         $page = $this->dispatch($found, $all);
                     }
                 } catch (ErrorException $e) {
                     $this->grav['log']->error('site.routes: ' . $pattern . '-> ' . $e->getMessage());
                 }
             }
         }
     }
     return $page;
 }
开发者ID:rikusv,项目名称:grav,代码行数:48,代码来源:Pages.php


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