本文整理汇总了PHP中redirect::send方法的典型用法代码示例。如果您正苦于以下问题:PHP redirect::send方法的具体用法?PHP redirect::send怎么用?PHP redirect::send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类redirect
的用法示例。
在下文中一共展示了redirect::send方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: routes
/**
* Registers all routes
*
* @param array $routes New routes
* @return array
*/
public function routes($routes = array())
{
// extend the existing routes
if (!empty($routes) and is_array($routes)) {
return $this->options['routes'] = array_merge($this->options['routes'], $routes);
}
$routes = $this->options['routes'];
$kirby = $this;
$site = $this->site();
if ($site->multilang()) {
foreach ($site->languages() as $lang) {
$routes[] = array('pattern' => ltrim($lang->url . '/(:all?)', '/'), 'method' => 'ALL', 'lang' => $lang, 'action' => function ($path = null) use($kirby, $site) {
return $site->visit($path, $kirby->route->lang->code());
});
}
// fallback for the homepage
$routes[] = array('pattern' => '/', 'method' => 'ALL', 'action' => function () use($kirby, $site) {
// check if the language detector is activated
if ($kirby->option('language.detect')) {
if (s::get('language') and $language = $kirby->site()->sessionLanguage()) {
// $language is already set but the user wants to
// select the default language
$referer = r::referer();
if (!empty($referer) && str::startsWith($referer, $this->urls()->index())) {
$language = $kirby->site()->defaultLanguage();
}
} else {
// detect the user language
$language = $kirby->site()->detectedLanguage();
}
} else {
// always use the default language if the detector is disabled
$language = $kirby->site()->defaultLanguage();
}
// redirect to the language homepage if necessary
if ($language->url != '/' and $language->url != '') {
go($language->url());
}
// plain home pages
return $site->visit('/', $language->code());
});
}
// tinyurl handling
$routes['tinyurl'] = $this->component('tinyurl')->route();
// home redirect
$routes['homeRedirect'] = array('pattern' => $this->options['home'], 'action' => function () {
redirect::send(page('home')->url(), 307);
});
// plugin assets
$routes['pluginAssets'] = array('pattern' => 'assets/plugins/(:any)/(:all)', 'method' => 'GET', 'action' => function ($plugin, $path) use($kirby) {
$root = $kirby->roots()->plugins() . DS . $plugin . DS . 'assets' . DS . $path;
$file = new Media($root);
if ($file->exists()) {
return new Response(f::read($root), f::extension($root));
} else {
return new Response('The file could not be found', f::extension($path), 404);
}
});
// all other urls
$routes['others'] = array('pattern' => '(:all)', 'method' => 'ALL', 'action' => function ($path = null) use($site, $kirby) {
// visit the currently active page
$page = $site->visit($path);
// react on errors for invalid URLs
if ($page->isErrorPage() and $page->uri() != $path) {
// get the filename
$filename = rawurldecode(basename($path));
$pagepath = dirname($path);
// check if there's a page for the parent path
if ($page = $site->find($pagepath)) {
// check if there's a file for the last element of the path
if ($file = $page->file($filename)) {
go($file->url());
}
}
// return the error page if there's no such page
return $site->errorPage();
}
return $page;
});
return $routes;
}