本文整理汇总了PHP中ModelAsController::find_old_page方法的典型用法代码示例。如果您正苦于以下问题:PHP ModelAsController::find_old_page方法的具体用法?PHP ModelAsController::find_old_page怎么用?PHP ModelAsController::find_old_page使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ModelAsController
的用法示例。
在下文中一共展示了ModelAsController::find_old_page方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleRequest
/**
* This acts the same as {@link Controller::handleRequest()}, but if an action cannot be found this will attempt to
* fall over to a child controller in order to provide functionality for nested URLs.
*
* @return SS_HTTPResponse
*/
public function handleRequest(SS_HTTPRequest $request)
{
$child = null;
$action = $request->param('Action');
// If nested URLs are enabled, and there is no action handler for the current request then attempt to pass
// control to a child controller. This allows for the creation of chains of controllers which correspond to a
// nested URL.
if ($action && SiteTree::nested_urls() && !$this->hasAction($action)) {
// See ModelAdController->getNestedController() for similar logic
Translatable::disable_locale_filter();
// look for a page with this URLSegment
$child = DataObject::get_one('SiteTree', sprintf("\"ParentID\" = %s AND \"URLSegment\" = '%s'", $this->ID, Convert::raw2sql($action)));
Translatable::enable_locale_filter();
// if we can't find a page with this URLSegment try to find one that used to have
// that URLSegment but changed. See ModelAsController->getNestedController() for similiar logic.
if (!$child) {
$child = ModelAsController::find_old_page($action, $this->ID);
if ($child) {
$response = new SS_HTTPResponse();
$params = $request->getVars();
if (isset($params['url'])) {
unset($params['url']);
}
$response->redirect(Controller::join_links($child->Link(Controller::join_links($request->param('ID'), $request->param('OtherID'))), $params ? '?' . http_build_query($params) : null), 301);
return $response;
}
}
}
// we found a page with this URLSegment.
if ($child) {
$request->shiftAllParams();
$request->shift();
$response = ModelAsController::controller_for($child)->handleRequest($request);
} else {
// If a specific locale is requested, and it doesn't match the page found by URLSegment,
// look for a translation and redirect (see #5001). Only happens on the last child in
// a potentially nested URL chain.
if ($request->getVar('locale') && $this->dataRecord && $this->dataRecord->Locale != $request->getVar('locale')) {
$translation = $this->dataRecord->getTranslation($request->getVar('locale'));
if ($translation) {
$response = new SS_HTTPResponse();
$response->redirect($translation->Link(), 301);
throw new SS_HTTPResponse_Exception($response);
}
}
Director::set_current_page($this->data());
$response = parent::handleRequest($request);
Director::set_current_page(null);
}
return $response;
}
示例2: testFindOldPage
/**
*
* NOTE: This test requires nested_urls
*
*/
function testFindOldPage()
{
$page = new Page();
$page->Title = 'First Level';
$page->URLSegment = 'oldurl';
$page->write();
$page->publish('Stage', 'Live');
$page->URLSegment = 'newurl';
$page->write();
$page->publish('Stage', 'Live');
$response = ModelAsController::find_old_page('oldurl');
$this->assertEquals('First Level', $response->Title);
$page2 = new Page();
$page2->Title = 'Second Level Page';
$page2->URLSegment = 'oldpage2';
$page2->ParentID = $page->ID;
$page2->write();
$page2->publish('Stage', 'Live');
$page2->URLSegment = 'newpage2';
$page2->write();
$page2->publish('Stage', 'Live');
$response = ModelAsController::find_old_page('oldpage2', $page2->ParentID);
$this->assertEquals('Second Level Page', $response->Title);
$response = ModelAsController::find_old_page('oldpage2', $page2->ID);
$this->assertEquals(false, $response);
}