當前位置: 首頁>>代碼示例>>PHP>>正文


PHP ModelAsController::controller_for方法代碼示例

本文整理匯總了PHP中ModelAsController::controller_for方法的典型用法代碼示例。如果您正苦於以下問題:PHP ModelAsController::controller_for方法的具體用法?PHP ModelAsController::controller_for怎麽用?PHP ModelAsController::controller_for使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ModelAsController的用法示例。


在下文中一共展示了ModelAsController::controller_for方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: get_navbar_html

 public static function get_navbar_html($page = null)
 {
     // remove the protocol from the URL, otherwise we run into https/http issues
     $url = self::remove_protocol_from_url(self::get_toolbar_hostname());
     $static = true;
     if (!$page instanceof SiteTree) {
         $page = Director::get_current_page();
         $static = false;
     }
     // In some cases, controllers are bound to "mock" pages, like Security. In that case,
     // throw the "default section" as the current controller.
     if (!$page instanceof SiteTree || !$page->isInDB()) {
         $controller = ModelAsController::controller_for($page = SiteTree::get_by_link(Config::inst()->get('GlobalNav', 'default_section')));
     } else {
         // Use controller_for to negotiate sub controllers, e.g. /showcase/listing/slug
         // (Controller::curr() would return the nested RequestHandler)
         $controller = ModelAsController::controller_for($page);
     }
     // Ensure staging links are not exported to the nav
     $origStage = Versioned::current_stage();
     Versioned::reading_stage('Live');
     $html = ViewableData::create()->customise(array('ToolbarHostname' => $url, 'Scope' => $controller, 'ActivePage' => $page, 'ActiveParent' => $page instanceof SiteTree && $page->Parent()->exists() ? $page->Parent() : $page, 'StaticRender' => $static, 'GoogleCustomSearchId' => Config::inst()->get('GlobalNav', 'google_search_id')))->renderWith('GlobalNavbar');
     Versioned::reading_stage($origStage);
     return $html;
 }
開發者ID:newleeland,項目名稱:silverstripe-globaltoolbar,代碼行數:25,代碼來源:GlobalNavSiteTreeExtension.php

示例2: GetRootPages

 public function GetRootPages()
 {
     $controllers = new ArrayList();
     $pageModels = Page::get()->filter(array("ParentId" => 0, "ID:not" => AllInOneHelper::excludedPageIds()));
     foreach ($pageModels as $model) {
         $controllers->push(ModelAsController::controller_for($model));
     }
     return $controllers;
 }
開發者ID:ramana-devasani,項目名稱:silverstripe-all-in-one-page,代碼行數:9,代碼來源:AllInOnePage_Controller.php

示例3: onBeforeHTTPError

 /**
  *	Retrieve the correct error page for the current multisite instance.
  *	@param integer
  *	@param SS_HTTPRequest
  *	@throws SS_HTTPResponse_Exception
  */
 public function onBeforeHTTPError($code, $request)
 {
     $errorPage = ErrorPage::get()->filter(array('ErrorCode' => $code, 'SiteID' => Multisites::inst()->getCurrentSiteId()))->first();
     if ($errorPage) {
         Requirements::clear();
         Requirements::clear_combined_files();
         $response = ModelAsController::controller_for($errorPage)->handleRequest($request, DataModel::inst());
         throw new SS_HTTPResponse_Exception($response, $code);
     }
 }
開發者ID:helpfulrobot,項目名稱:sheadawson-silverstripe-multisites,代碼行數:16,代碼來源:MultisitesControllerExtension.php

示例4: index

 /**
  * Runs the permissiion checks, and setup of the controller view.
  */
 public function index()
 {
     if (!Director::isDev() && !Permission::check('ADMIN')) {
         return Security::permissionFailure();
     }
     $page = Page::get()->first();
     $controller = ModelAsController::controller_for($page);
     $controller->init();
     return $controller->customise($this->getStyleGuideData())->renderWith(array('SimpleStyleguideController', 'Page'));
 }
開發者ID:benmanu,項目名稱:silverstripe-simple-styleguide,代碼行數:13,代碼來源:SimpleStyleguideController.php

示例5: Link

 /**
  * @param string $action
  * @return string
  */
 public function Link($action = null)
 {
     $page = TrainingDirectoryPage::get()->first();
     if (is_null($page)) {
         return '';
     }
     $controller = ModelAsController::controller_for($page);
     if (is_null($controller)) {
         return '';
     }
     return $controller->Link($action);
 }
開發者ID:rbowen,項目名稱:openstack-org,代碼行數:16,代碼來源:Training_Controller.php

示例6: SearchForm

 /**
  * Site search form
  */
 public function SearchForm()
 {
     // Retrieve the search form input, excluding any filters.
     $form = ($page = $this->owner->getSearchPage()) && $page->SearchEngine ? ModelAsController::controller_for($page)->getForm(false) : null;
     // Update the search input to account for usability.
     if ($form) {
         $search = $form->Fields()->dataFieldByName('Search');
         $search->setAttribute('placeholder', $search->Title());
         $search->setTitle('');
     }
     return $form;
 }
開發者ID:helpfulrobot,項目名稱:nglasl-silverstripe-extensible-search,代碼行數:15,代碼來源:ExtensibleSearchExtension.php

示例7: getResponseController

 /**
  * Prepare the controller for handling the response to this request
  *
  * @param string $title Title to use
  * @return Controller
  */
 protected function getResponseController($title)
 {
     if (!class_exists('SiteTree')) {
         return $this;
     }
     // Use sitetree pages to render the opauth pages
     $tmpPage = new Page();
     $tmpPage->ID = -1;
     $tmpPage->Title = $title;
     $controller = ModelAsController::controller_for($tmpPage);
     $controller->init();
     return $controller;
 }
開發者ID:betterbrief,項目名稱:silverstripe-opauth,代碼行數:19,代碼來源:OpauthController.php

示例8: Link

 /**
  * @param string $action
  * @return string
  */
 public function Link($action = null)
 {
     $class = $this->getDirectoryPageClass();
     $page = $class::get()->first();
     if (is_null($page)) {
         return '';
     }
     $controller = ModelAsController::controller_for($page);
     if (is_null($controller)) {
         return '';
     }
     return $controller->Link($action);
 }
開發者ID:OpenStackweb,項目名稱:openstack-org,代碼行數:17,代碼來源:Cloud_Controller.php

示例9: response_for

 /**
  * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an {@link ErrorPage} for that code is present.
  *
  * @param int $statusCode
  * @return SS_HTTPResponse
  */
 public static function response_for($statusCode)
 {
     // first attempt to dynamically generate the error page
     if ($errorPage = DataObject::get_one('ErrorPage', "\"ErrorCode\" = {$statusCode}")) {
         return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
     }
     // then fall back on a cached version
     $cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
     if (file_exists($cachedPath)) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($statusCode);
         $response->setBody(file_get_contents($cachedPath));
         return $response;
     }
 }
開發者ID:prostart,項目名稱:cobblestonepath,代碼行數:21,代碼來源:ErrorPage.php

示例10: testValidation

 public function testValidation()
 {
     $validator = new OrderActionsForm_Validator('PaymentMethod');
     $form = new OrderActionsForm(ModelAsController::controller_for($this->checkoutPage), 'ActionsForm', $this->order);
     $validator->setForm($form);
     Form::set_current_action('dopayment');
     $validator->php(array('OrderID' => $this->order->ID, 'PaymentMethod' => 'Dummy', 'type' => 'visa', 'name' => 'Tester Mc. Testerson', 'number' => '4242424242424242'));
     $requiredCount = 0;
     foreach ($validator->getErrors() as $error) {
         if ($error['messageType'] == 'required') {
             $requiredCount++;
         }
     }
     // 3 required fields missing
     $this->assertEquals(3, $requiredCount);
 }
開發者ID:burnbright,項目名稱:silverstripe-shop,代碼行數:16,代碼來源:OrderActionsFormTest.php

示例11: response_for

 /**
  * Get a {@link SS_HTTPResponse} to response to a HTTP error code if an
  * {@link ErrorPage} for that code is present. First tries to serve it 
  * through the standard SilverStripe request method. Falls back to a static
  * file generated when the user hit's save and publish in the CMS
  *
  * @param int $statusCode
  *
  * @return SS_HTTPResponse
  */
 public static function response_for($statusCode)
 {
     // first attempt to dynamically generate the error page
     $errorPage = ErrorPage::get()->filter(array("ErrorCode" => $statusCode))->first();
     if ($errorPage) {
         Requirements::clear();
         Requirements::clear_combined_files();
         return ModelAsController::controller_for($errorPage)->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
     }
     // then fall back on a cached version
     $cachedPath = self::get_filepath_for_errorcode($statusCode, class_exists('Translatable') ? Translatable::get_current_locale() : null);
     if (file_exists($cachedPath)) {
         $response = new SS_HTTPResponse();
         $response->setStatusCode($statusCode);
         $response->setBody(file_get_contents($cachedPath));
         return $response;
     }
 }
開發者ID:riddler7,項目名稱:silverstripe-cms,代碼行數:28,代碼來源:ErrorPage.php

示例12: getControllerForSearchForm

 /**
  *
  * @return ContentController
  */
 public function getControllerForSearchForm()
 {
     $controllerName = Config::inst()->get('CustomSearch', 'search_controller');
     if ($controllerName == 'this') {
         return $this->owner;
     }
     if (class_exists($controllerName)) {
         $obj = Object::create($controllerName);
         if ($obj instanceof SiteTree && ($page = $controllerName::get()->first())) {
             return ModelAsController::controller_for($page);
         }
         if ($obj instanceof Controller) {
             return $obj;
         }
     }
     //fallback:
     //@todo: throw notice
     return $this->owner;
 }
開發者ID:nblum,項目名稱:silverstripe-searchable-dataobjects,代碼行數:23,代碼來源:CustomSearch.php

示例13: onBeforeInit

 /**
  * @return SS_HTTPResponse
  */
 public function onBeforeInit()
 {
     $config = SiteConfig::current_site_config();
     // If Maintenance Mode is Off, skip processing
     if (!$config->MaintenanceMode) {
         return;
     }
     // Check if the visitor is Admin OR if they have an allowed IP.
     if (Permission::check('VIEW_SITE_MAINTENANCE_MODE') || Permission::check('ADMIN') || $this->hasAllowedIP()) {
         return;
     }
     // Are we already on the UtilityPage? If so, skip processing.
     if ($this->owner instanceof UtilityPage_Controller) {
         return;
     }
     // Fetch our utility page instance now.
     /**
      * @var Page $utilityPage
      */
     $utilityPage = UtilityPage::get()->first();
     if (!$utilityPage) {
         return;
     }
     // We need a utility page before we can do anything.
     // Are we configured to prevent redirection to the UtilityPage URL?
     if ($utilityPage->config()->DisableRedirect) {
         // Process the request internally to ensure that the URL is maintained
         // (instead of redirecting to the maintenance page's URL) and skip any further processing.
         $controller = ModelAsController::controller_for($utilityPage);
         $response = $controller->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
         HTTP::add_cache_headers($response);
         $response->output();
         die;
     }
     // Default: Skip any further processing and immediately respond with a redirect to the UtilityPage.
     $response = new SS_HTTPResponse();
     $response->redirect($utilityPage->AbsoluteLink(), 302);
     HTTP::add_cache_headers($response);
     $response->output();
     die;
 }
開發者ID:hemant-chakka,項目名稱:awss,代碼行數:44,代碼來源:MaintenanceModeExtension.php

示例14: _getAnnouncement

 public function _getAnnouncement($render = true)
 {
     if (ClassInfo::hasTable('MediaHolder')) {
         $media = MediaHolder::get()->filter(array('MediaType.Title' => 'News'));
         $possible = $media->first();
         // what about an announcement title'd page
         $page = $media->filter(array('Title' => 'Announcements'))->first();
         if (!$page) {
             $page = $possible;
         }
         if ($page) {
             $announcement = MediaPage::get()->filter('ParentID', $page->ID)->sort('Date DESC')->first();
             if ($announcement) {
                 if (!$render) {
                     return $announcement;
                 } else {
                     return ModelAsController::controller_for($announcement)->index();
                 }
             }
         }
     }
 }
開發者ID:helpfulrobot,項目名稱:silverstripe-australia-intranet-sis,代碼行數:22,代碼來源:AnnouncementDashlet.php

示例15: GetLayoutTemplate

 /**
  * Returns the Layout template based on the current ClassName
  * @return {mixed} template to be rendered
  * */
 public function GetLayoutTemplate()
 {
     $res = "";
     try {
         if (class_exists($this->owner->ClassName)) {
             $controller = ModelAsController::controller_for($this->owner);
             $controller->setSession(Controller::curr()->getSession());
             $controller->init();
             $viewer = $controller->getViewer("index");
             $templates = $viewer->templates();
             if (isset($templates["Layout"])) {
                 $layoutViewer = Injector::inst()->create("SSViewer", $templates["Layout"]);
                 $layoutViewer->setPartialCacheStore($viewer->getPartialCacheStore());
                 $viewer = $layoutViewer;
             }
             $res = $viewer->process($controller);
         }
     } catch (Exception $exc) {
         //            echo $exc->getTraceAsString();
     }
     return $res;
 }
開發者ID:ramana-devasani,項目名稱:silverstripe-all-in-one-page,代碼行數:26,代碼來源:AllInOnePageExtension.php


注:本文中的ModelAsController::controller_for方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。