本文整理汇总了PHP中LeftAndMain::handleAction方法的典型用法代码示例。如果您正苦于以下问题:PHP LeftAndMain::handleAction方法的具体用法?PHP LeftAndMain::handleAction怎么用?PHP LeftAndMain::handleAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LeftAndMain
的用法示例。
在下文中一共展示了LeftAndMain::handleAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleAction
/**
* Overloaded to avoid "action doesn't exist" errors - all URL parts in this controller are virtual and handled through handleRequest(), not controller methods.
* @param {SS_HTTPRequest} $request
* @param {string} $action
* @return {SS_HTTPResponse}
*/
public function handleAction($request, $action)
{
// if we submitted a form, let that pass
if (!$request->isGET()) {
return parent::handleAction($request, $action);
}
$url = $request->getURL();
//If the current request has an extension attached to it, strip that off and redirect the user to the page without an extension.
if (DocumentationHelper::get_extension($url)) {
$request->shift();
$request->shift();
return $this->redirect(Director::absoluteURL(DocumentationHelper::trim_extension_off($url)) . '/', 301);
}
//Strip off the base url
$base = ltrim(Config::inst()->get('DocumentationViewer', 'link_base'), '/');
if ($base && strpos($url, $base) !== false) {
$url = substr(ltrim($url, '/'), strlen($base));
}
//Handle any permanent redirections that the developer has defined.
if ($link = DocumentationPermalinks::map($url)) {
$request->shift();
$request->shift();
//the first param is a shortcode for a page so redirect the user to the short code.
return $this->redirect($link, 301);
}
//Validate the language provided. Language is a required URL parameter. as we use it for generic interfaces and language selection.
//If language is not set, redirects to 'en'
$languages = i18n::get_common_languages();
if (!($lang = $request->param('Lang'))) {
$lang = $request->param('Action');
$action = $request->param('ID');
} else {
$action = $request->param('Action');
}
if (!$lang) {
return $this->redirect($this->Link('en'));
} else {
if (!isset($languages[$lang])) {
return $this->httpError(404);
}
}
$request->shift(10);
$allowed = $this->config()->allowed_actions;
if (in_array($action, $allowed)) {
//if it's one of the allowed actions such as search or all then the URL must be prefixed with one of the allowed languages.
return parent::handleAction($request, $action);
} else {
//look up the manifest to see find the nearest match against the list of the URL. If the URL exists then set that as the current page to match against. strip off any extensions.
if ($record = $this->getManifest()->getPage($url)) {
$this->record = $record;
return $this->getResponseNegotiator()->respond($request);
} else {
if ($redirect = $this->getManifest()->getRedirect($url)) {
$to = Controller::join_links(Director::baseURL(), $base, $redirect);
return $this->redirect($to, 301);
} else {
if (!$url || $url == $lang) {
return $this->getResponseNegotiator()->respond($request);
} else {
$url = explode('/', $url);
$url = implode('/', array_map(function ($a) {
return DocumentationHelper::clean_page_url($a);
}, $url));
if ($record = $this->getManifest()->getPage($url)) {
return $this->redirect($record->Link(), 301);
}
}
}
}
}
return $this->httpError(404);
}