当前位置: 首页>>代码示例>>PHP>>正文


PHP ModelAsController::find_old_page方法代码示例

本文整理汇总了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;
 }
开发者ID:hamishcampbell,项目名称:silverstripe-sapphire,代码行数:57,代码来源:ContentController.php

示例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);
 }
开发者ID:SustainableCoastlines,项目名称:loveyourwater,代码行数:31,代码来源:ModelAsControllerTest.php


注:本文中的ModelAsController::find_old_page方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。