本文整理汇总了PHP中Grav\Common\Grav::redirect方法的典型用法代码示例。如果您正苦于以下问题:PHP Grav::redirect方法的具体用法?PHP Grav::redirect怎么用?PHP Grav::redirect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Grav
的用法示例。
在下文中一共展示了Grav::redirect方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: redirect
/**
* Redirects an action
*/
public function redirect()
{
if ($this->redirect) {
$this->grav->redirect($this->redirect, $this->redirectCode);
} else {
if ($redirect = $this->grav['config']->get('plugins.login.redirect')) {
$this->grav->redirect($redirect, $this->redirectCode);
}
}
}
示例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'];
// Try redirects
$redirect = $config->get("site.redirects.{$url}");
if ($redirect) {
$this->grav->redirect($redirect);
}
// See if route matches one in the site configuration
$route = $config->get("site.routes.{$url}");
if ($route) {
$page = $this->dispatch($route, $all);
} else {
// Try looking for wildcards
foreach ($config->get("site.routes") as $alias => $route) {
$match = rtrim($alias, '*');
if (strpos($alias, '*') !== false && strpos($url, $match) !== false) {
$wildcard_url = str_replace('*', str_replace($match, '', $url), $route);
$page = isset($this->routes[$wildcard_url]) ? $this->get($this->routes[$wildcard_url]) : null;
if ($page) {
return $page;
}
}
}
}
}
return $page;
}
示例3: redirect
/**
* Redirect to the route stored in $this->redirect
*/
public function redirect()
{
if (!$this->redirect) {
return;
}
$base = $this->admin->base;
$this->redirect = '/' . ltrim($this->redirect, '/');
$multilang = $this->isMultilang();
$redirect = '';
if ($multilang) {
// if base path does not already contain the lang code, add it
$langPrefix = '/' . $this->grav['session']->admin_lang;
if (!Utils::startsWith($base, $langPrefix . '/')) {
$base = $langPrefix . $base;
}
// now the first 4 chars of base contain the lang code.
// if redirect path already contains the lang code, and is != than the base lang code, then use redirect path as-is
if (Utils::pathPrefixedByLangCode($base) && Utils::pathPrefixedByLangCode($this->redirect) && substr($base, 0, 4) != substr($this->redirect, 0, 4)) {
$redirect = $this->redirect;
} else {
if (!Utils::startsWith($this->redirect, $base)) {
$this->redirect = $base . $this->redirect;
}
}
} else {
if (!Utils::startsWith($this->redirect, $base)) {
$this->redirect = $base . $this->redirect;
}
}
if (!$redirect) {
$redirect = $this->redirect;
}
$this->grav->redirect($redirect, $this->redirectCode);
}
示例4: redirect
/**
* Redirect to the route stored in $this->redirect
*/
public function redirect()
{
if (!$this->redirect) {
return;
}
$base = $this->admin->base;
$path = trim(substr($this->redirect, 0, strlen($base)) == $base ? substr($this->redirect, strlen($base)) : $this->redirect, '/');
$this->grav->redirect($base . '/' . preg_replace('|/+|', '/', $path), $this->redirectCode);
}
示例5: redirect
/**
* Redirects an action
*/
public function redirect()
{
$redirect = $this->grav['config']->get('plugins.newsletter.admin.subscriber.enable.redirect');
if (!$redirect) {
$this->grav->redirect($redirect, $this->redirectCode);
} else {
if ($this->redirect) {
$this->grav->redirect($this->redirect, $this->redirectCode);
}
}
}
示例6: 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->redirect($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;
}
示例7: redirect
/**
* Redirects an action
*/
public function redirect()
{
if ($this->redirect) {
$this->grav->redirect($this->redirect, $this->redirectCode);
}
}