In addition to creating pages with drag and drop parts, you can also create rich pages using PHP. These 'Code Behind' pages can provide custom content and functionality, mixed seamlessly with your site. This custom content can also be mixed with the built in drag and drop parts, allowing you to combine both on the same page.
For example, in these screenshots the News section of the site has been created using a Code Behind page. The actual news content is mixed in seamlessly with the other content already on the site, including the advertisement and navigation.
Click to Enlarge
In edit page mode you can see the content that has been created in the CodeBehind page (highlighted with arrow).
Click to Enlarge
To create a CodeBehind page, create an empty PHP file in your
site\control directory. This file can be created with any name or in any subfolder. The framework will find any CodeBehind file that you create, treating the control directory as if it is your WebRoot.
In this example I've created a page called hello.php. I could reach this page by browsing to "www.mysite.com\hello"
After creating the page you will need to fill it with some simple PHP code:
<?php
/*===========================================================
CodeBehind Page
Hello World sample page
============================================================*/
class pageHello extends page {
/*===========================================================
MEMBER VARIABLES
============================================================*/
var $layout = "Columns1";
/*===========================================================
AREA 2 - Center Page Content
============================================================*/
function area2(){
$this->title = "Sample CodeBehind Page";
$this->border = 1;
return "Hello World!";
}
}
?>
Here I've created a simple CodeBehind page that will place the words "HelloWorld" in the center of the page (area2) with the title "Sample CodeBehind Page" above it.
CodeBehind pages are created by defining a class that extends the page class. The class must be named "page" followed by the name of the file. In this case "pageHello".
Within the class functions are created that control the contents of different 'areas'. Where these areas are rendered depends on the current theme and layout being used.
As a rule of thumb area1 is a sidebar and area2 is the center of the page.. These functions return a string of HTML that will be rendered.
When we browse to this sample page, it will look something similar to the following:
Click to Enlarge
In this example we've created a very simple CodeBehind page. CodeBehind files also provide a large set of features (not covered here) that make it easy to create custom content. Other features include
templating, ajax, eventing, and multiple view support. For more details on creating CodeBehind pages, please see the CodeBehind Section of the documentation.