Next: Context

BMC/UUP-SITE - Rendering

Rendering can be done either direct from each script or implicit by the dispatcher. Classes deriving from the standard page class should define the printContent() method used as the callback to output web content.

Direct rendering

The script is responsible for setting up includes, creating the page object and call its render() method. For web sites this is quickly becoming messy as the autoload script has to be located somehow.

<?php

require_once('vendor/autoload.php');

use UUP\Site\Page\StandardPage;

class IndexPage extends StandardPage
{

        public function printContent()
        {
                include("index.inc");           // Load the view
        }

}

$page = new IndexPage();
$page->render();

Dispatcher (page routing)

When page routing is used, the dispather has already included the composer autoloader and takes care of creating the page object and call its render method. This is the prefered solution as it enables you to focus on the content.

<?php

use UUP\Site\Page\Web\StandardPage;

class IndexPage extends StandardPage
{

        public function printContent()
        {
                include("index.inc");           // Load the view
        }

}

Simple content (views)

When a dispatcher is user for rendering the page (*.php), then the script don't have to declare a page class. It could contain just plain HTML that is wrapped in a view class by the dispather that is then rendered.

Because of the wrapping, the script has access to the $this pointer and can access all services usually available inside your page objects. More examples is included in example directory in the source package.