本文整理汇总了PHP中Grav\Common\Page\Page::routable方法的典型用法代码示例。如果您正苦于以下问题:PHP Page::routable方法的具体用法?PHP Page::routable怎么用?PHP Page::routable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Grav\Common\Page\Page
的用法示例。
在下文中一共展示了Page::routable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: register
public function register(Container $container)
{
$container['page'] = function ($c) {
/** @var Grav $c */
/** @var Pages $pages */
$pages = $c['pages'];
/** @var Language $language */
$language = $c['language'];
/** @var Uri $uri */
$uri = $c['uri'];
$path = $uri->path();
// Don't trim to support trailing slash default routes
$path = $path ?: '/';
$page = $pages->dispatch($path);
// Redirection tests
if ($page) {
if ($c['config']->get('system.force_ssl')) {
if (!isset($_SERVER['HTTPS']) || $_SERVER["HTTPS"] != "on") {
$url = "https://" . $_SERVER["HTTP_HOST"] . $_SERVER["REQUEST_URI"];
$c->redirect($url);
}
}
$url = $page->route();
if ($uri->params()) {
if ($url == '/') {
//Avoid double slash
$url = $uri->params();
} else {
$url .= $uri->params();
}
}
if ($uri->query()) {
$url .= '?' . $uri->query();
}
if ($uri->fragment()) {
$url .= '#' . $uri->fragment();
}
// Language-specific redirection scenarios
if ($language->enabled()) {
if ($language->isLanguageInUrl() && !$language->isIncludeDefaultLanguage()) {
$c->redirect($url);
}
if (!$language->isLanguageInUrl() && $language->isIncludeDefaultLanguage()) {
$c->redirectLangSafe($url);
}
}
// Default route test and redirect
if ($c['config']->get('system.pages.redirect_default_route') && $page->route() != $path) {
$c->redirectLangSafe($url);
}
}
// if page is not found, try some fallback stuff
if (!$page || !$page->routable()) {
// Try fallback URL stuff...
$c->fallbackUrl($path);
if (!$page) {
$path = $c['locator']->findResource('system://pages/notfound.md');
$page = new Page();
$page->init(new \SplFileInfo($path));
$page->routable(false);
}
}
return $page;
};
}