Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

How do I have "special" pages were the content is generated by a PHP script?


Go to End


5 Posts   1590 Views

Avatar
MKayHavoc

Community Member, 33 Posts

3 June 2008 at 2:39am

Hi,

Might sound a bit strange, but I'm wondering how I can have pages on a site that are kind of managed by the CMS as in they appear in the navigation etc, but the content of the page is generated by a custom PHP script.

For example I have a script that generates a telephone directory and displays it, how would this integrate into the CMS?

Cheers

Avatar
Willr

Forum Moderator, 5523 Posts

3 June 2008 at 8:27pm

just create a page type MyPage.php then create one of these in the CMS. Then in the MyPage_Controller you can overload a method called Content to set the content from your PHP Script instead of the Content from the CMS or use a MyPage template to send custom content

Avatar
MKayHavoc

Community Member, 33 Posts

3 June 2008 at 9:02pm

OK, sound sensible. How do I create a custom page type?

Avatar
Willr

Forum Moderator, 5523 Posts

3 June 2008 at 9:14pm

Read the second tutorial so you have the understanding behind this but create a file named whatever for this example ill call it DirectoryPage.php. Create this in the mysite/code folder

<?php

class DirectoryPage extends Page {

static $db = array();

}
class DirectoryPage_Controller extends Page_Controller {

function Content() {
// your php function
return $SomeText;
}

}

Then visit http://www.yoursite.com/db/build?flush=1. Next in the CMS you need to create a new page of type - DirectoryPage and you should have a custom page. Read tthe tutorials for a bigger overview

Avatar
MKayHavoc

Community Member, 33 Posts

3 June 2008 at 9:27pm

Ah, that's great. OK, i'll read the tutorial for more details. Cheers.