本文整理汇总了PHP中ModelAsController::handleRequest方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelAsController::handleRequest方法的具体用法?PHP ModelAsController::handleRequest怎么用?PHP ModelAsController::handleRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelAsController
的用法示例。
在下文中一共展示了ModelAsController::handleRequest方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
/**
* @uses ModelAsController::getNestedController()
* @param SS_HTTPRequest $request
* @param DataModel $model
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
// Check Translatable dependency
if (!class_exists('Translatable') || !SiteTree::has_extension('Translatable') && !SiteTree::has_extension('LanguagePrefixTranslatable')) {
throw new Exception('Dependency error: the LanguagePrefix module expects the Translatable module.');
}
$disablePrefixForDefaultLang = Config::inst()->get('prefixconfig', 'disable_prefix_for_default_lang');
$firstSegment = $request->param('URLSegment');
if ($firstSegment) {
$prefixUsed = $this->setLocale($firstSegment);
$defaultLocale = Translatable::default_locale();
$isDefaultLocale = $this->locale == $defaultLocale;
if ($prefixUsed) {
if ($isDefaultLocale && $disablePrefixForDefaultLang) {
$url = substr($request->getURL(true), strlen($firstSegment));
return $this->redirect($url, 301);
} else {
$request->shiftAllParams();
$request->shift(1);
}
} else {
/*
* if no prefix is used but $disablePrefixForDefaultLang
* is set, we go on like nothing happened. Otherwise a
* 404 is generated. @todo: maybe we should redirect
* pages that do actually exist, because this is a bit
* harsh?
*/
//if (!$isDefaultLocale || !$disablePrefixForDefaultLang) {
// return $this->showPageNotFound();
//}
}
}
return parent::handleRequest($request, $model);
}
示例2: handleRequest
public function handleRequest($request) {
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment().'/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
示例3: testFindOldPage
public function testFindOldPage()
{
$page = new Page();
$page->Title = 'Test Page';
$page->URLSegment = 'test-page';
$page->write();
$page->publish('Stage', 'Live');
$page->URLSegment = 'test';
$page->write();
$page->publish('Stage', 'Live');
$router = new ModelAsController();
$request = new HTTPRequest('GET', 'test-page/action/id/otherid');
$request->match('$URLSegment/$Action/$ID/$OtherID');
$response = $router->handleRequest($request);
$this->assertEquals($response->getHeader('Location'), Controller::join_links(Director::baseURL() . 'test/action/id/otherid'));
}
示例4: handleRequest
public function handleRequest($request)
{
self::$is_at_root = true;
$this->pushCurrent();
$this->init();
// If the basic database hasn't been created, then build it.
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new HTTPResponse();
$this->redirect("dev/build?returnURL=");
return $this->response;
}
$controller = new ModelAsController();
$request = new HTTPRequest("GET", self::get_homepage_urlsegment() . '/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$result = $controller->handleRequest($request);
$this->popCurrent();
return $result;
}
示例5: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$action = $request->param('Action');
$result = parent::handleRequest($request, $model);
if (!$action && AllInOneHelper::shouldProcess($request, $result->getStatusCode())) {
$realController = $this->getNestedController();
$parentId = intval($realController->ParentID);
$currentPageId = intval($realController->ID);
if ($parentId === 0 && !AllInOneHelper::isPageIdExluded($currentPageId)) {
$jsMin = Director::isDev() ? "" : ".min";
Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery' . $jsMin . '.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui' . $jsMin . '.js');
Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
Requirements::javascript('silverstripe-all-in-one-page/javascript/dist/AllInOnePage' . $jsMin . '.js');
$tmpContoller = Injector::inst()->create("AllInOnePage_Controller", $realController->data());
if ($this->session) {
$tmpContoller->setSession($this->session);
}
$result = $tmpContoller->handleRequest($this->request, $model);
}
}
return $result;
}
开发者ID:helpfulrobot,项目名称:gdmedia-silverstripe-all-in-one-page,代码行数:23,代码来源:AllInOneModelAsController.php
示例6: handleRequest
/**
* @param SS_HTTPRequest $request
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$request = new SS_HTTPRequest($request->httpMethod(), self::get_homepage_link() . '/', $request->getVars(), $request->postVars());
$request->match('$URLSegment//$Action', true);
$controller = new ModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}
示例7: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
$this->setRequest($request);
// Check for existing routing parameters, redirecting to another locale automatically if necessary
$locale = Fluent::get_request_locale();
if (empty($locale)) {
// Determine if this user should be redirected
$locale = $this->getRedirectLocale();
$this->extend('updateRedirectLocale', $locale);
// Check if the user should be redirected
$domainDefault = Fluent::default_locale(true);
if (Fluent::is_locale($locale) && $locale !== $domainDefault) {
// Check new traffic with detected locale
return $this->redirect(Fluent::locale_baseurl($locale));
}
// Reset parameters to act in the default locale
$locale = $domainDefault;
Fluent::set_persist_locale($locale);
$params = $request->routeParams();
$params[Fluent::config()->query_param] = $locale;
$request->setRouteParams($params);
}
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$localeURL = Fluent::alias($locale);
$request->setUrl(self::fluent_homepage_link($localeURL));
$request->match($localeURL . '/$URLSegment//$Action', true);
$controller = new ModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}
示例8: handleRequest
public function handleRequest($request) {
$this->request = $request;
return parent::handleRequest($request);
}
示例9: getNestedController
public function getNestedController()
{
$url = Director::urlParams();
$hasUrlSegment = false;
$parent = null;
$counter = 1;
foreach ($this->urlParams as $urlSegment) {
$hasUrlSegment = true;
$SQL_URLSegment = Convert::raw2sql($urlSegment);
$filter = "URLSegment = '{$SQL_URLSegment}'";
if (isset($child)) {
$filter .= "AND ParentID = {$child->ID}";
} else {
$filter .= "AND ParentID = 0";
}
$child = DataObject::get_one('SiteTree', $filter);
if (!$child) {
$key = $counter - 2;
if ($key < 0) {
$key = 0;
}
$this->mapParams($key);
$c = new ModelAsController();
$this->request->setParams($this->urlParams);
return $c->handleRequest($this->request);
}
if (isset($child->UrlParentID) && $child->UrlParentID != 0) {
$parent = $child->UrlParent();
} else {
if (isset($child->ParentID) && $child->ParentID != 0) {
$parent = $child->Parent();
} else {
$parent = null;
}
}
if ($parent && $parent->URLSegment != 'home') {
$keyint = $counter - 1;
$key = "url" . $keyint;
if (!isset($this->urlParams[$key]) || $parent->URLSegment != $this->urlParams[$key]) {
$child = $this->get404Page();
break;
}
}
$counter++;
}
if ($hasUrlSegment) {
if (!$child) {
if ($child = $this->findOldPage($SQL_URLSegment)) {
$url = Controller::join_links(Director::baseURL(), $child->URLSegment, isset($this->urlParams['Action']) ? $this->urlParams['Action'] : null, isset($this->urlParams['ID']) ? $this->urlParams['ID'] : null, isset($this->urlParams['OtherID']) ? $this->urlParams['OtherID'] : null);
$response = new HTTPResponse();
$response->redirect($url, 301);
return $response;
}
$child = $this->get404Page();
}
if ($child) {
$this->mapParams();
if (isset($_REQUEST['debug'])) {
Debug::message("Using record #{$child->ID} of type {$child->class} with URL {$this->urlParams['URLSegment']}");
}
// set language
if ($child->Locale) {
Translatable::set_current_locale($child->Locale);
}
$controllerClass = "{$child->class}_Controller";
if ($this->urlParams['Action'] && ClassInfo::exists($controllerClass . '_' . $this->urlParams['Action'])) {
$controllerClass = $controllerClass . '_' . $this->urlParams['Action'];
}
if (ClassInfo::exists($controllerClass)) {
$controller = new $controllerClass($child);
} else {
$controller = $child;
}
return $controller;
} else {
return new HTTPResponse("The requested page couldn't be found.", 404);
}
} else {
user_error("NestedUrlController not geting a URLSegment. It looks like the site isn't redirecting to home", E_USER_ERROR);
}
}
示例10: handleRequest
/**
* @uses ModelAsController::getNestedController()
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->request = $request;
$this->setDataModel($model);
$this->pushCurrent();
//Get the local from the language param
if (Config::inst()->get('MultilingualRootURLController', 'UseLocaleURL')) {
if (Config::inst()->get('MultilingualRootURLController', 'UseDashLocale')) {
//Language is missing a dash 404
if (strpos($request->param('Language'), '-') === false) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
}
$locale = explode('-', $request->param('Language'));
$locale[1] = strtoupper($locale[1]);
//Make sure that the language is all lowercase
if ($request->param('Language') == implode('-', $locale)) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
}
$locale = implode('_', $locale);
} else {
$locale = $request->param('Language');
}
} else {
if (strpos($request->param('Language'), '_') !== false) {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
} else {
$locale = i18n::get_locale_from_lang($request->param('Language'));
}
}
if (in_array($locale, Translatable::get_allowed_locales())) {
//Set the current locale and remember it
Cookie::set('language', $request->param('Language'));
Translatable::set_current_locale($locale);
i18n::set_locale($locale);
} else {
//Locale not found 404
if ($response = ErrorPage::response_for(404)) {
return $response;
} else {
$this->httpError(404, 'The requested page could not be found.');
}
return $this->response;
}
//Handle the home page for the language
$urlSegment = $request->param('URLSegment');
if (empty($urlSegment)) {
$controller = new MultilingualRootURLController();
$response = $controller->handleRequest($request, $model);
$this->popCurrent();
return $response;
}
//Normal page request so handle that
$response = parent::handleRequest($request, $model);
$this->popCurrent();
return $response;
}
开发者ID:helpfulrobot,项目名称:webbuilders-group-silverstripe-translatablerouting,代码行数:78,代码来源:MultilingualModelAsController.php