本文整理汇总了PHP中RootURLController::get_homepage_link方法的典型用法代码示例。如果您正苦于以下问题:PHP RootURLController::get_homepage_link方法的具体用法?PHP RootURLController::get_homepage_link怎么用?PHP RootURLController::get_homepage_link使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RootURLController
的用法示例。
在下文中一共展示了RootURLController::get_homepage_link方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: contentcontrollerInit
public function contentcontrollerInit()
{
if ($this->owner->hasExtension('Translatable')) {
// get locale according to host
$hostLoc = LocaleDomains::getLocaleFromHost();
// get locale according to settings
$currLoc = Translatable::get_current_locale();
// check if locales differ
if ($hostLoc != $currLoc && !in_array($this->owner->URLSegment, self::$ignored_url_segments)) {
// check if homepage called. if so, set target locale to domain locale
$targetLoc = $currLoc;
if ($this->owner->URLSegment == RootURLController::get_homepage_link()) {
$targetLoc = $hostLoc;
}
// check if page has translation in target locale. if so, get translation
$targetPage = $this->owner;
if ($this->owner->hasTranslation($targetLoc)) {
$targetPage = $this->owner->getTranslation($targetLoc);
}
// redirect to target domain with target page
if ($targetPage) {
Controller::curr()->redirect(Controller::join_links(Director::protocol() . LocaleDomains::getHostFromLocale($targetLoc), $targetPage->RelativeLink()));
}
}
}
}
示例2: 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;
}
示例3: 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());
}
示例4: 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());
}
示例5: 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);
}
}
示例6: 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();
}
示例7: 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;
}
示例8: 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;
}
示例9: AddForm
/**
* @return Form
*/
function AddForm() {
// If request send from rightclick-submenu, directly add Page
if(($pageType = $this->request->getVar('Type')) && ($parentID = $this->request->getVar('ParentID'))) {
$data = array(
"PageType" => (string)$pageType,
"ParentID" => $parentID,
"ParentModeField" => "child"
);
$this->doAdd($data, null);
return;
}
$record = $this->currentPage();
$pageTypes = array();
foreach($this->PageTypes() as $type) {
$html = sprintf('<span class="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(
// new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null),
// TODO Should be part of the form attribute, but not possible in current form API
$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, //new LiteralField("Dummy", ''),
"child//$childTitle" => $parentField = new TreeDropdownField(
"ParentID",
"",
'SiteTree'
)
)
),
$typeField = new OptionsetField(
"PageType",
sprintf($numericLabelTmpl, 2, _t('CMSMain.ChoosePageType', 'Choose page type')),
$pageTypes,
'Page'
)
);
$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(
// $resetAction = new ResetFormAction('doCancel', _t('CMSMain.Cancel', 'Cancel')),
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;
}
示例10: get_by_link
/**
* Alternative implementation that takes into account the current site
* as the root
*
* @param type $link
* @param type $cache
* @return boolean
*/
public static function get_by_link($link, $cache = true)
{
$current = Multisites::inst()->getCurrentSiteId();
if (trim($link, '/')) {
$link = trim(Director::makeRelative($link), '/');
} else {
$link = RootURLController::get_homepage_link();
}
$parts = Convert::raw2sql(preg_split('|/+|', $link));
// Grab the initial root level page to traverse down from.
$URLSegment = array_shift($parts);
$sitetree = DataObject::get_one('SiteTree', "\"URLSegment\" = '{$URLSegment}' AND \"ParentID\" = " . $current, $cache);
if (!$sitetree) {
return false;
}
/// Fall back on a unique URLSegment for b/c.
if (!$sitetree && self::nested_urls() && ($page = DataObject::get('SiteTree', "\"URLSegment\" = '{$URLSegment}'")->First())) {
return $page;
}
// Check if we have any more URL parts to parse.
if (!count($parts)) {
return $sitetree;
}
// Traverse down the remaining URL segments and grab the relevant SiteTree objects.
foreach ($parts as $segment) {
$next = DataObject::get_one('SiteTree', "\"URLSegment\" = '{$segment}' AND \"ParentID\" = {$sitetree->ID}", $cache);
if (!$next) {
return false;
}
$sitetree->destroy();
$sitetree = $next;
}
return $sitetree;
}
示例11: RelativeLink
/**
* Return the link for this {@link SiteTree} object relative to the SilverStripe root.
*
* By default, it this page is the current home page, and there is no action specified then this will return a link
* to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten
* and returned in its full form.
*
* @uses RootURLController::get_homepage_link()
* @param string $action
* @return string
*/
public function RelativeLink($action = null)
{
if ($this->ParentID && self::nested_urls()) {
$base = $this->Parent()->RelativeLink($this->URLSegment);
} else {
$base = $this->URLSegment;
}
// Unset base for homepage URLSegments in their default language.
// Homepages with action parameters or in different languages
// need to retain their URLSegment. We can only do this if the homepage
// is on the root level.
if (!$action && $base == RootURLController::get_homepage_link() && !$this->ParentID) {
$base = null;
if ($this->hasExtension('Translatable') && $this->Locale != Translatable::default_locale()) {
$base = $this->URLSegment;
}
}
if (is_string($action)) {
$action = str_replace('&', '&', $action);
} elseif ($action === true) {
$action = null;
}
return Controller::join_links($base, '/', $action);
}
示例12: currentPageID
public function currentPageID()
{
$id = parent::currentPageID();
$this->extend('updateCurrentPageID', $id);
// Fall back to homepage record
if (!$id) {
$homepageSegment = RootURLController::get_homepage_link();
$homepageRecord = DataObject::get_one('SiteTree', sprintf('"SiteTree"."URLSegment" = \'%s\'', Convert::raw2sql($homepageSegment)));
if ($homepageRecord) {
$id = $homepageRecord->ID;
}
}
return $id;
}
示例13: RelativeLink
/**
* Return the link for this {@link SiteTree} object relative to the SilverStripe root.
*
* By default, if this page is the current home page, and there is no action specified then this will return a link
* to the root of the site. However, if you set the $action parameter to TRUE then the link will not be rewritten
* and returned in its full form.
*
* @uses RootURLController::get_homepage_link()
*
* @param string $action See {@link Link()}
* @return string
*/
public function RelativeLink($action = null)
{
if ($this->ParentID && self::config()->nested_urls) {
$base = $this->Parent()->RelativeLink($this->URLSegment);
} elseif (!$action && $this->URLSegment == RootURLController::get_homepage_link()) {
// Unset base for root-level homepages.
// Note: Homepages with action parameters (or $action === true)
// need to retain their URLSegment.
$base = null;
} else {
$base = $this->URLSegment;
}
$this->extend('updateRelativeLink', $base, $action);
// Legacy support: If $action === true, retain URLSegment for homepages,
// but don't append any action
if ($action === true) {
$action = null;
}
return Controller::join_links($base, '/', $action);
}
示例14: currentPageID
public function currentPageID()
{
$id = parent::currentPageID();
// Fall back to homepage record
if (!$id) {
$homepageSegment = RootURLController::get_homepage_link();
$homepageRecord = DataObject::get_one('SiteTree', sprintf('"URLSegment" = \'%s\'', $homepageSegment));
if ($homepageRecord) {
$id = $homepageRecord->ID;
}
}
return $id;
}
示例15: handleRequest
public function handleRequest(SS_HTTPRequest $request, DataModel $model = null)
{
self::$is_at_root = true;
$this->setDataModel($model);
$this->pushCurrent();
$this->init();
$this->setRequest($request);
// Check for existing routing parameters, redirecting to another locale automatically if necessary
$locale = Fluent::get_request_locale();
if (empty($locale)) {
// Determine if this user should be redirected
$locale = $this->getRedirectLocale();
$this->extend('updateRedirectLocale', $locale);
// Check if the user should be redirected
$domainDefault = Fluent::default_locale(true);
if (Fluent::is_locale($locale) && $locale !== $domainDefault) {
// Check new traffic with detected locale
return $this->redirect(Fluent::locale_baseurl($locale));
}
// Reset parameters to act in the default locale
$locale = $domainDefault;
Fluent::set_persist_locale($locale);
$params = $request->routeParams();
$params[Fluent::config()->query_param] = $locale;
$request->setRouteParams($params);
}
if (!DB::isActive() || !ClassInfo::hasTable('SiteTree')) {
$this->response = new SS_HTTPResponse();
$this->response->redirect(Director::absoluteBaseURL() . 'dev/build?returnURL=' . (isset($_GET['url']) ? urlencode($_GET['url']) : null));
return $this->response;
}
$localeURL = Fluent::alias($locale);
$request->setUrl($localeURL . '/' . RootURLController::get_homepage_link() . '/');
$request->match($localeURL . '/$URLSegment//$Action', true);
$controller = new ModelAsController();
$result = $controller->handleRequest($request, $model);
$this->popCurrent();
return $result;
}