class my_document_controller extends base_controller {
public function my_document_controller(){
}
public function transformContent(){
}
}Moreover, the base_controller inherits all attributes and functions of the class APFObject.
Besindes, each document controller instance contains a reference on the current DOM node the controller is responsible for transformation. The reference is stored in the $this->__Document variable. Using this reference, you can access the document's foo attribute via
$this->__Document->getAttribute('foo')Due to usability reasons, the document controller also knows all attributes of the current document to transform. These are stored within the internal class variable $this->__Attributes and can directly be accessed within the document controller.
<@controller namespace="sites::apfdocupage::pres::templates::documentcontroller" file="website_v1_controller"
class="website_v1_controller" @>
[..]
<meta name="DC.Date" content="<html:placeholder name="Date" />" />
<meta name="DC.Type" content="Text" />
<meta name="DC.Format" content="text/html" />
<meta name="DC.Identifier" content="Dipl.-Ing. (FH) Christian W. Achatz" />
<meta name="DC.Source" content="<html:placeholder name="URI" />" />
<meta name="DC.Language" content="de" />
<meta name="DC.Relation" content="<html:placeholder name="URI" />" />
[..]
<meta name="keywords" lang="de" content="PHP,Framework,PageController,FrontController,Pattern,[..]" />
<meta name="date" content="<html:placeholder name="Date" />" />
<meta name="robots" content="index,follow" />
<meta name="revisit-after" content="5 days" />
[..]class website_v1_controller extends base_controller {
function website_v1_controller(){
}
function transformContent(){
// Set placeholder "URI"
$this->setPlaceHolder('URI',$_SERVER['REQUEST_URI']);
// Set placeholder "Date"
$this->setPlaceHolder('Date',date('Y-m-d'));
}
}<@controller namespace="sites::apfdocupage::pres::templates::documentcontroller" file="list_v1_controller"
class="list_v1_controller" @>
[..]
<html:placeholder name="List" />
<html:template name="ListHeader">
<table cellpadding="0" cellspacing="0" border="0">
<tr>
<td>
<strong>ExampleList</strong>
</td>
</tr>
<template:placeholder name="TableElements" />
</table>
</html:template>
<html:template name="ListItem">
<tr>
<td>
<template:placeholder name="ItemValue" />
</td>
</tr>
</html:template>import('sites::demosite::biz','listLoader');
class list_v1_controller extends base_controller {
function list_v1_controller(){
}
function transformContent(){
// Set list to placehodler "List"
$this->setPlaceHolder('List',$this->__buildList());
}
function __buildList(){
// Create listLoader
$listLoader = &$this->__getServiceObject('sites::demosite::biz','listLoader');
// Load list
$List = $listLoader->loadList();
// Initialize HTML buffer
$Buffer = (string)'';
// Get a reference of the "Header" template
$Template__ListHeader = &$this->__getTemplate('ListHeader');
// Walk through the list and generate an item
foreach($List as $lKey => $lItem){
// Generate the HTML code of an item and add it to the buffer
$Buffer .= $this->__buildListItem($lItem);
}
// Set items into the "Header" template
$Template__ListHeader->setPlaceHolder('TableElements',$Buffer);
// Transform the template transformieren and return the code
return $Template__ListHeader->transformTemplate();
}
function __buildListItem(&$listItem){
// Get a reference if the "ListItem" template
$Template__ListItem = &$this->__getTemplate('ListItem');
// Fill place holder of the template
$Template__ListItem->setPlaceHolder('ItemValue',$listItem->get('ListContent'));
// Transform the template transformieren and return the code
return $Template__ListItem->transformTemplate();
}
}