Banshee PHP framework

Adding a page

Banshee has two kind of pages. A module and a virtual page. A module is a page which has a module, a view and a controller file on disk and can be used to create dynamic pages. A virtual page is stored in the database and displayed via the page module, of which the Banshee framework takes care. A virtual page is always static.

Adding a module

To add a module to your website, copy 'templates/page_view.xslt' to 'view/<page_id>.xslt'. Add <page_id> to 'settings/public_pages.conf' if the page should be accessible to all visitors or to 'settings/private_pages.conf' if a login is required. Run 'database/private_pages' when you've changed 'settings/private_pages.conf'. The new page is accessible via http://hostname/<page_id>. The associated controller and module are 'controllers/<page_id>.php' and 'modules/<page_id>.php'.

Creating output

Banshee uses XSLT as view templates. Within the controller and model class, the $this->output object can be used to create the XML file, which will be used with the XSLT file to create the output. How to use the output object can be read in the output library documentation. The XSLT view file should include 'includes/banshee.xslt' and should have a template which matches the XML tag named 'content'. The 'content' XML tag is created by the Banshee framework and does therefor not need to be created by the controller.

Example view file:

<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:include href="includes/banshee.xslt" />

<xsl:template match="content">
<h1>Page title</h1>
<xsl:value-of select="data" />
</xsl:template>

</xsl:stylesheet>

OO programming

Banshee requires OO programming. The controller and model should both be classes and must extend the 'controller' / 'model' class. The controller class must be named '<page_id>_controller', the model class must be named '<page_id>_model'. You can use 'templates/page_controller.php' or 'templates/page_model.php' to start your controller or model file. The controller class should have at least a function called 'execute'. In both controller and model class, the variables $this->db, $this->settings, $this->user, $this->page and $this->output are available, which are objects of the classes MySQLi_connection, settings, user, page and output. In the controller, the private variable $this->model is available, which is an object of the associated model class for that page (when available).

An OO controller file looks like this:

<?php
  class page_controller extends controller {
    public function execute() {
      if (($data $this->model->get_data(123)) === false) {
        $this->output->add_tag("result""Data not found.");
      } else {
        $this->output->add_tag("data""Data: ".$data);
      }
    }
  }
?>

An OO model file looks like this:

<?php
  class page_model extends model {
    public function get_data($id) {
      return $this->db->entry("table"$id);
    }
  }
?>

Since Banshee 3.1, a script called 'new_module' is available, which can create a new module for you based on the files in the templates directory. It is located in the root directory of a Banshee website.

Adding a virtual page

To add a virtual page, login as a user which as access to the Page Administation (/admin/page) CMS page. Go to that page and click on the 'New page' button.