Documenation

Creating pages

The easiest way to add a page to your website is using the Page plugin. After installation you'll find a link on the Dashboard where you can add and edit pages. These pages can only contain static content such as text and images and are useful for simple documents and articles.

To add a dynamic (scripted) page you need to create two files, a Controller and a View.

Example Controller (/hello.php)

01
02
03
04
05
06
07
08
09
10
11
12
13
14
<?php
$contrSetup 
= array(
    
'rootPath'  => './',
    
'pageTitle' => 'Hello'
    
);

require(
$contrSetup['rootPath'] . '_model/init.php');

// Your code goes here

$view->load('hello.html.php');

$model->end();
?>

The $contrSetup variable is a requirement that lets you configure the Controller. The value of rootPath is the relative path to the root directory, in this case ./. If you place the controller in a subdirectory it should be ../ or perhaps ../../.

The next step is to initialize Model by including /_model/init.php. Without the Model you won't be able to use any of Swiftlet's functions.

At this point you can add your own PHP code.

Now you can load the View file with $view->load(). This file will contain all the HTML and other UI elements. This way logic is separated from design which will make it easier to maintain.

Finally you need to call $model->end() to finalize the request. This will make sure database connections are closed, sessions are saved and output is sent to the browser.

When you browse to the Controller (/hello.php) in your web browser the page should appear.

See also