本文整理汇总了PHP中ModelAsController类的典型用法代码示例。如果您正苦于以下问题:PHP ModelAsController类的具体用法?PHP ModelAsController怎么用?PHP ModelAsController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ModelAsController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: run
public function run($requestParams)
{
self::$is_at_root = true;
$this->pushCurrent();
$controller = new ModelAsController();
$controller->setUrlParams(array('URLSegment' => self::get_homepage_urlsegment(), 'Action' => ''));
$result = $controller->run($requestParams);
$this->popCurrent();
return $result;
}
示例2: 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;
}
示例3: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model)
{
$this->pushCurrent();
$this->urlParams = $request->allParams();
$this->request = $request;
$this->response = new SS_HTTPResponse();
$this->setDataModel($model);
$urlsegment = $request->param('URLSegment');
$this->extend('onBeforeInit');
$this->init();
$this->extend('onAfterInit');
// First check products against URL segment
if ($product = Product::get()->filter(array('URLSegment' => $urlsegment, 'Disabled' => 0))->first()) {
$controller = Catalogue_Controller::create($product);
} elseif ($category = ProductCategory::get()->filter('URLSegment', $urlsegment)->first()) {
$controller = Catalogue_Controller::create($category);
} else {
// If CMS is installed
if (class_exists('ModelAsController')) {
$controller = ModelAsController::create();
}
}
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}
示例4: 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;
}
示例5: 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);
}
示例6: 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'));
}
示例7: 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;
}
示例8: 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;
}
示例9: 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
示例10: 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'));
}
示例11: 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);
}
示例12: 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
示例13: 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;
}
示例14: 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);
}
示例15: 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;
}
}