21288 Posts in 5733 Topics by 2602 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 722 Views |
-
Dynamically create redirector page

6 January 2011 at 4:18pm
The following code creates a new page:
$p = new Page();
$p->Title = 'Hello';
$p->MenuTitle = $p->Title;
$p->URLSegment = $p->Title;
$p->Content = '';
$p->Status = 'Published';
$p->write();
$p->doRestoreToStage();
$p->publish('Stage', 'Live');
$p->flushCache();
How can I create a redirector page that redirects to / ?I don't want a normal page, when someone goes to this URL I want them to be redirected to the home page.
-
Re: Dynamically create redirector page

6 January 2011 at 8:43pm
How can I create a redirector page that redirects to / ?
I don't want a normal page, when someone goes to this URL I want them to be redirected to the home page.Well instead of creating a new Page(); create a new RedirectorPage();
You also then need to set the fields to point to the page it redirects to. Via
$p->RedirectionType = 'Internal';
$p->ExternalURLID = DataObject::get_one('SiteTree', "URLSegment = 'home'"); -
Re: Dynamically create redirector page

7 January 2011 at 8:35am
Perfect, thanks! Now how can I keep that item from showing up in the menu? I can't figure out how to use ShowInMenus with this.
-
Re: Dynamically create redirector page

7 January 2011 at 6:56pm
$p->ShowInMenus = 0; // or false should also work.
-
Re: Dynamically create redirector page

28 July 2011 at 11:36am
How can I validate the urlsegment page already exists before creating the dynamic page?
| 722 Views | ||
|
Page:
1
|
Go to Top |



