<?php
 
require_once('SimpleTPL.class.php');
 
 
// Simple example
 
$tpl =& new SimpleTPL();
 
 
$name = 'Patrick J. Mizer';
 
 
$attributes = array (    'University' => 'University of Texas at Austin',
 
                        'Major' => 'Computer Science',
 
                        'GPA' => '4.0 (it\'s my example, I can embellish)');
 
 
 
$tpl->assignValue('name', $name);
 
$tpl->assignValue('attributes', $attributes);
 
 
$tpl->renderTemplate('header.tpl.php');
 
$tpl->renderTemplate('demo.tpl.php');
 
$tpl->renderTemplate('footer.tpl.php');
 
 
$tpl->cleanUp();
 
 
// For a more practical example imagine we have a MVC setup
 
// with a controller class defined something like...
 
 
class someController
 
{ 
 
    function serveModule($mod){
 
        
 
        $tpl2 =& new SimpleTPL();
 
        
 
        if(class_exists($mod)){
 
            $view =& new $mod();
 
    
 
            $tpl2->renderTemplate('header.tpl.php');
 
            $view->processRequest();
 
            $tpl2->renderTemplate('footer.tpl.php');
 
    
 
            $tpl2->cleanUp();
 
            $view->cleanUp();
 
        }else{
 
            echo 'Class: ' . $mod . ' DNE';
 
        }
 
    }
 
}
 
 
// ... and a view class defined like...
 
 
class SomeView extends SimpleTPL
 
{
 
    function processRequest()
 
    {
 
        if(!isset($_REQUEST['action'])){
 
            $this->drawStudentInformation();
 
        }
 
        
 
    }
 
    
 
    function drawStudentInformation()
 
    {
 
        $name = 'Patrick J. Mizer';
 
 
        $attributes = array (    'University' => 'University of Texas at Austin',
 
                                'Major' => 'Computer Science',
 
                                'GPA' => '4.0 (it\'s my example, I can embellish)');
 
        
 
        $this->assignValue('name', $name);
 
        $this->assignValue('attributes', $attributes);
 
        
 
        $this->renderTemplate('demo.tpl.php');
 
    }
 
}
 
 
// The client code would be something like...
 
 
$cntrlr =& new someController();
 
$cntrlr->serveModule('someView');
 
 
// ... and voila.
 
 
// I think this example illustrates how using templates (no matter how simple) 
 
// really cleans up your code via encapsulation. Coupling this paradigm with 
 
// the use of DAO's makes for very managable, portable, extendable PHP code.
 
 
?>
 
 
 |