本文整理汇总了PHP中RootURLController类的典型用法代码示例。如果您正苦于以下问题:PHP RootURLController类的具体用法?PHP RootURLController怎么用?PHP RootURLController使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RootURLController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testNestedPages
/**
* Test that nested pages, basic actions, and nested/non-nested URL switching works properly
*/
public function testNestedPages()
{
RootURLController::reset();
SiteTree::enable_nested_urls();
$this->assertEquals('Home Page', $this->get('/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/index/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/second-index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/second-index/')->getBody());
RootURLController::reset();
SiteTree::disable_nested_urls();
$this->assertEquals('Home Page', $this->get('/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/second-index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/second-index/')->getBody());
}
示例2: init
public function init()
{
parent::init();
// If we've accessed the homepage as /home/, then we should redirect to /.
if ($this->dataRecord && $this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) && (!isset($this->urlParams['Action']) || !$this->urlParams['Action']) && !$_POST && !$_FILES && !$this->redirectedTo()) {
$getVars = $_GET;
unset($getVars['url']);
if ($getVars) {
$url = "?" . http_build_query($getVars);
} else {
$url = "";
}
$this->redirect($url, 301);
return;
}
if ($this->dataRecord) {
$this->dataRecord->extend('contentcontrollerInit', $this);
} else {
singleton('SiteTree')->extend('contentcontrollerInit', $this);
}
if ($this->redirectedTo()) {
return;
}
// Check page permissions
if ($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->canView()) {
return Security::permissionFailure($this);
}
// Use theme from the site config
if (($config = SiteConfig::current_site_config()) && $config->Theme) {
Config::inst()->update('SSViewer', 'theme', $config->Theme);
}
}
示例3: getEditForm
/**
* @return Form
*/
public function getEditForm($id = null, $fields = null)
{
$siteConfig = SiteConfig::current_site_config();
$fields = $siteConfig->getCMSFields();
// Tell the CMS what URL the preview should show
$fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link()));
// Added in-line to the form, but plucked into different view by LeftAndMain.Preview.js upon load
$fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()));
$navField->setAllowHTML(true);
$actions = $siteConfig->getCMSActions();
$form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm');
$form->setResponseNegotiator($this->getResponseNegotiator());
$form->addExtraClass('cms-content center cms-edit-form');
// don't add data-pjax-fragment=CurrentForm, its added in the content template instead
if ($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
}
$form->setHTMLID('Form_EditForm');
$form->loadDataFrom($siteConfig);
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
// Use <button> to allow full jQuery UI styling
$actions = $actions->dataFields();
if ($actions) {
foreach ($actions as $action) {
$action->setUseButtonTag(true);
}
}
$this->extend('updateEditForm', $form);
return $form;
}
示例4: testNestedPages
/**
* Test that nested pages, basic actions, and nested/non-nested URL switching works properly
*/
public function testNestedPages()
{
RootURLController::reset();
Config::inst()->update('SiteTree', 'nested_urls', true);
$this->assertEquals('Home Page', $this->get('/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/index/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/home/second-level/second-index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/home/second-level/third-level/second-index/')->getBody());
RootURLController::reset();
SiteTree::config()->nested_urls = false;
$this->assertEquals('Home Page', $this->get('/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/')->getBody());
$this->assertEquals('Home Page', $this->get('/home/second-index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/index/')->getBody());
$this->assertEquals('Second Level Page', $this->get('/second-level/second-index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/index/')->getBody());
$this->assertEquals('Third Level Page', $this->get('/third-level/second-index/')->getBody());
}
示例5: testGetHomepageLink
public function testGetHomepageLink() {
$default = $this->objFromFixture('Page', 'home');
SiteTree::disable_nested_urls();
$this->assertEquals('home', RootURLController::get_homepage_link());
SiteTree::enable_nested_urls();
$this->assertEquals('home', RootURLController::get_homepage_link());
}
示例6: testGetHomepageLink
public function testGetHomepageLink()
{
$default = $this->objFromFixture('Page', 'home');
SiteTree::config()->nested_urls = false;
$this->assertEquals('home', RootURLController::get_homepage_link());
Config::inst()->update('SiteTree', 'nested_urls', true);
$this->assertEquals('home', RootURLController::get_homepage_link());
}
示例7: testHomepageForDomain
function testHomepageForDomain()
{
$originalHost = $_SERVER['HTTP_HOST'];
// Tests matching an HTTP_HOST value to URLSegment homepage values
$tests = array('page.co.nz' => 'page1', 'www.page.co.nz' => 'page1', 'help.com' => 'page1', 'www.help.com' => 'page1', 'something.com' => 'page1', 'www.something.com' => 'page1', 'other.co.nz' => 'page2', 'www.other.co.nz' => 'page2', 'right' => 'page2', 'www. right' => 'page2', 'only.com' => 'page3', 'www.only.com' => 'page3', 'www.somethingelse.com' => 'home', 'somethingelse.com' => 'home', 'alternate.only.com' => 'home', 'www.alternate.only.com' => 'home', 'alternate.something.com' => 'home');
foreach ($tests as $domain => $urlSegment) {
$_SERVER['HTTP_HOST'] = $domain;
$this->assertEquals($urlSegment, RootURLController::get_homepage_urlsegment(Translatable::default_locale()), "Testing {$domain} matches {$urlSegment}");
}
$_SERVER['HTTP_HOST'] = $originalHost;
}
示例8: onBeforeHTTPError404
/**
* On every URL that generates a 404, we'll capture it here and see if we can
* find an old URL that it should be redirecting to.
*
* @param SS_HTTPRequest $request The request object
* @throws SS_HTTPResponse_Exception
*/
public function onBeforeHTTPError404($request)
{
// We need to get the URL ourselves because $request->allParams() only has a max of 4 params
$params = preg_split('|/+|', $request->getURL());
$cleanURL = trim(Director::makeRelative($request->getURL(false), '/'));
$getvars = $request->getVars();
unset($getvars['url']);
$page = self::find_old_page($params);
$cleanPage = trim(Director::makeRelative($page), '/');
if (!$cleanPage) {
$cleanPage = Director::makeRelative(RootURLController::get_homepage_link());
}
if ($page && $cleanPage != $cleanURL) {
$res = new SS_HTTPResponse();
$res->redirect(Controller::join_links($page, $getvars ? '?' . http_build_query($getvars) : null), 301);
throw new SS_HTTPResponse_Exception($res);
}
}
示例9: init
public function init()
{
parent::init();
// If we've accessed the homepage as /home/, then we should redirect to /.
if ($this->dataRecord && $this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) && (!isset($this->urlParams['Action']) || !$this->urlParams['Action']) && !$_POST && !$_FILES && !$this->redirectedTo()) {
$getVars = $_GET;
unset($getVars['url']);
if ($getVars) {
$url = "?" . http_build_query($getVars);
} else {
$url = "";
}
$this->redirect($url, 301);
return;
}
if ($this->dataRecord) {
$this->dataRecord->extend('contentcontrollerInit', $this);
} else {
singleton('SiteTree')->extend('contentcontrollerInit', $this);
}
if ($this->redirectedTo()) {
return;
}
// Check page permissions
if ($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->canView()) {
return Security::permissionFailure($this);
}
// Draft/Archive security check - only CMS users should be able to look at stage/archived content
if ($this->URLSegment != 'Security' && !Session::get('unsecuredDraftSite') && (Versioned::current_archived_date() || Versioned::current_stage() && Versioned::current_stage() != 'Live')) {
if (!$this->dataRecord->canViewStage(Versioned::current_archived_date() ? 'Stage' : Versioned::current_stage())) {
$link = $this->Link();
$message = _t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>');
Session::clear('currentStage');
Session::clear('archiveDate');
$permissionMessage = sprintf(_t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", 'You must log in with your CMS password in order to view the draft or archived content. ' . '<a href="%s">Click here to go back to the published site.</a>'), Controller::join_links($this->Link(), "?stage=Live"));
return Security::permissionFailure($this, $permissionMessage);
}
}
// Use theme from the site config
if (($config = SiteConfig::current_site_config()) && $config->Theme) {
Config::inst()->update('SSViewer', 'theme', $config->Theme);
}
}
示例10: testGetHomepageLink
public function testGetHomepageLink()
{
$default = $this->objFromFixture('Page', 'home');
$nested = $this->objFromFixture('Page', 'nested');
SiteTree::disable_nested_urls();
$this->assertEquals('home', RootURLController::get_homepage_link());
SiteTree::enable_nested_urls();
$this->assertEquals('home', RootURLController::get_homepage_link());
$nested->HomepageForDomain = str_replace('www.', null, $_SERVER['HTTP_HOST']);
$nested->write();
RootURLController::reset();
SiteTree::disable_nested_urls();
$this->assertEquals('nested-home', RootURLController::get_homepage_link());
RootURLController::reset();
SiteTree::enable_nested_urls();
$this->assertEquals('home/nested-home', RootURLController::get_homepage_link());
$nested->HomepageForDomain = null;
$nested->write();
}
示例11: init
public function init()
{
parent::init();
//Log page views
Statistics::collect();
// If we've accessed the homepage as /home/, then we should redirect to /.
if ($this->dataRecord && $this->dataRecord instanceof SiteTree && RootURLController::should_be_on_root($this->dataRecord) && !$this->urlParams['Action'] && !$_POST && !$_FILES && !Director::redirected_to()) {
$getVars = $_GET;
unset($getVars['url']);
if ($getVars) {
$url = "?" . http_build_query($getVars);
} else {
$url = "";
}
Director::redirect($url);
return;
}
if ($this->dataRecord) {
$this->dataRecord->extend('contentcontrollerInit', $this);
} else {
singleton('SiteTree')->extend('contentcontrollerInit', $this);
}
if (Director::redirected_to()) {
return;
}
Director::set_site_mode('site');
// Check page permissions
if ($this->dataRecord && $this->URLSegment != 'Security' && !$this->dataRecord->can('View')) {
Security::permissionFailure($this);
}
// Draft/Archive security check - only CMS users should be able to look at stage/archived content
if ($this->URLSegment != 'Security' && (Versioned::current_archived_date() || Versioned::current_stage() && Versioned::current_stage() != 'Live')) {
if (!Permission::check('CMS_ACCESS_CMSMain')) {
$link = $this->Link();
$message = _t("ContentController.DRAFT_SITE_ACCESS_RESTRICTION", "You must log in with your CMS password in order to view the draft or archived content. <a href=\"%s\">Click here to go back to the published site.</a>");
Security::permissionFailure($this, sprintf($message, "{$link}?stage=Live"));
return;
}
}
}
示例12: getEditForm
/**
* @param null $id Not used.
* @param null $fields Not used.
* @return Form
*/
public function getEditForm($id = null, $fields = null)
{
$treeClass = $this->config()->get('tree_class');
$page = $treeClass::get()->first();
if (!$page || !$page->exists()) {
$currentStage = Versioned::current_stage();
Versioned::reading_stage('Stage');
$page = $treeClass::create();
$page->Title = $treeClass;
$page->write();
$page->doPublish();
Versioned::reading_stage($currentStage);
}
$fields = $page->getCMSFields();
$fields->push(new HiddenField('PreviewURL', 'Preview URL', RootURLController::get_homepage_link()));
$fields->push($navField = new LiteralField('SilverStripeNavigator', $this->getSilverStripeNavigator()));
$navField->setAllowHTML(true);
$actions = new FieldList();
$actions->push(FormAction::create('doSave', 'Save')->setUseButtonTag(true)->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept'));
$form = CMSForm::create($this, 'EditForm', $fields, $actions)->setHTMLID('Form_EditForm');
$form->setResponseNegotiator($this->getResponseNegotiator());
$form->addExtraClass('cms-content center cms-edit-form');
if ($form->Fields()->hasTabset()) {
$form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet');
}
$form->setHTMLID('Form_EditForm');
$form->loadDataFrom($page);
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
// Use <button> to allow full jQuery UI styling
$actions = $actions->dataFields();
if ($actions) {
foreach ($actions as $action) {
$action->setUseButtonTag(true);
}
}
$this->extend('updateEditForm', $form);
return $form;
}
示例13: AddForm
/**
* @return Form
*/
function AddForm()
{
$record = $this->currentPage();
$pageTypes = array();
foreach ($this->PageTypes() as $type) {
$html = sprintf('<span class="page-icon class-%s"></span><strong class="title">%s</strong><span class="description">%s</span>', $type->getField('ClassName'), $type->getField('AddAction'), $type->getField('Description'));
$pageTypes[$type->getField('ClassName')] = $html;
}
// Ensure generic page type shows on top
if (isset($pageTypes['Page'])) {
$pageTitle = $pageTypes['Page'];
$pageTypes = array_merge(array('Page' => $pageTitle), $pageTypes);
}
$numericLabelTmpl = '<span class="step-label"><span class="flyout">%d</span><span class="arrow"></span><span class="title">%s</span></span>';
$topTitle = _t('CMSPageAddController.ParentMode_top', 'Top level');
$childTitle = _t('CMSPageAddController.ParentMode_child', 'Under another page');
$fields = new FieldList($hintsField = new LiteralField('Hints', sprintf('<span class="hints" data-hints="%s"></span>', $this->SiteTreeHints())), new LiteralField('PageModeHeader', sprintf($numericLabelTmpl, 1, _t('CMSMain.ChoosePageParentMode', 'Choose where to create this page'))), $parentModeField = new SelectionGroup("ParentModeField", array("top//{$topTitle}" => null, "child//{$childTitle}" => $parentField = new TreeDropdownField("ParentID", "", 'SiteTree', 'ID', 'TreeTitle'))), $typeField = new OptionsetField("PageType", sprintf($numericLabelTmpl, 2, _t('CMSMain.ChoosePageType', 'Choose page type')), $pageTypes, 'Page'));
// TODO Re-enable search once it allows for HTML title display,
// see http://open.silverstripe.org/ticket/7455
// $parentField->setShowSearch(true);
$parentModeField->setValue($this->request->getVar('ParentID') ? 'child' : 'top');
$parentModeField->addExtraClass('parent-mode');
// CMSMain->currentPageID() automatically sets the homepage,
// which we need to counteract in the default selection (which should default to root, ID=0)
$homepageSegment = RootURLController::get_homepage_link();
if ($record && $record->URLSegment != $homepageSegment) {
$parentField->setValue($record->ID);
}
$actions = new FieldList(FormAction::create("doAdd", _t('CMSMain.Create', "Create"))->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')->setUseButtonTag(true));
$this->extend('updatePageOptions', $fields);
$form = new Form($this, "AddForm", $fields, $actions);
$form->addExtraClass('cms-add-form stacked cms-content center cms-edit-form ' . $this->BaseCSSClasses());
$form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
if ($parentID = $this->request->getVar('ParentID')) {
$form->Fields()->dataFieldByName('ParentID')->setValue((int) $parentID);
}
return $form;
}
示例14: testHomepageForDomain
function testHomepageForDomain() {
$originalHost = $_SERVER['HTTP_HOST'];
// Tests matching an HTTP_HOST value to URLSegment homepage values
$tests = array(
'page.co.nz' => 'page1',
'www.page.co.nz' => 'page1',
'help.com' => 'page1',
'www.help.com' => 'page1',
'something.com' => 'page1',
'www.something.com' => 'page1',
'other.co.nz' => 'page2',
'www.other.co.nz' => 'page2',
'right' => 'page2',
'www. right' => 'page2',
'only.com' => 'page3',
'www.only.com' => 'page3',
'www.somethingelse.com' => 'home',
'somethingelse.com' => 'home',
// Test some potential false matches to page2 and page3
'alternate.only.com' => 'home',
'www.alternate.only.com' => 'home',
'alternate.something.com' => 'home',
);
foreach($tests as $domain => $urlSegment) {
$_SERVER['HTTP_HOST'] = $domain;
$this->assertEquals($urlSegment, RootURLController::get_homepage_urlsegment(), "Testing $domain matches $urlSegment");
}
$_SERVER['HTTP_HOST'] = $originalHost;
}
示例15: setUp
function setUp()
{
// Mark test as being run
$this->originalIsRunningTest = self::$is_running_test;
self::$is_running_test = true;
// i18n needs to be set to the defaults or tests fail
i18n::set_locale(i18n::default_locale());
i18n::set_date_format(null);
i18n::set_time_format(null);
// Remove password validation
$this->originalMemberPasswordValidator = Member::password_validator();
$this->originalRequirements = Requirements::backend();
Member::set_password_validator(null);
Cookie::set_report_errors(false);
RootURLController::reset();
Translatable::reset();
Versioned::reset();
DataObject::reset();
SiteTree::reset();
Hierarchy::reset();
if (Controller::has_curr()) {
Controller::curr()->setSession(new Session(array()));
}
$this->originalTheme = SSViewer::current_theme();
// Save nested_urls state, so we can restore it later
$this->originalNestedURLsState = SiteTree::nested_urls();
$className = get_class($this);
$fixtureFile = eval("return {$className}::\$fixture_file;");
$prefix = defined('SS_DATABASE_PREFIX') ? SS_DATABASE_PREFIX : 'ss_';
// Set up fixture
if ($fixtureFile || $this->usesDatabase || !self::using_temp_db()) {
if (substr(DB::getConn()->currentDatabase(), 0, strlen($prefix) + 5) != strtolower(sprintf('%stmpdb', $prefix))) {
//echo "Re-creating temp database... ";
self::create_temp_db();
//echo "done.\n";
}
singleton('DataObject')->flushCache();
self::empty_temp_db();
foreach ($this->requireDefaultRecordsFrom as $className) {
$instance = singleton($className);
if (method_exists($instance, 'requireDefaultRecords')) {
$instance->requireDefaultRecords();
}
if (method_exists($instance, 'augmentDefaultRecords')) {
$instance->augmentDefaultRecords();
}
}
if ($fixtureFile) {
$fixtureFiles = is_array($fixtureFile) ? $fixtureFile : array($fixtureFile);
$i = 0;
foreach ($fixtureFiles as $fixtureFilePath) {
$fixture = new YamlFixture($fixtureFilePath);
$fixture->saveIntoDatabase();
$this->fixtures[] = $fixture;
// backwards compatibility: Load first fixture into $this->fixture
if ($i == 0) {
$this->fixture = $fixture;
}
$i++;
}
}
$this->logInWithPermission("ADMIN");
}
// Set up email
$this->originalMailer = Email::mailer();
$this->mailer = new TestMailer();
Email::set_mailer($this->mailer);
Email::send_all_emails_to(null);
// Preserve memory settings
$this->originalMemoryLimit = ini_get('memory_limit');
}