I'm trying to get a handle on the CompositView pattern, I think I have it, but maybe not
PHP Code:require_once(MAIN_LIB.'/html/class.TemplateBuilder.php');
abstract class View{
public $template;
function renderView(){
return $this->template->getParsedTemplate();
}
}
class DefaultModuleView extends View {
function __construct(){
$this->template = new TemplateBuilder("defaultView.html");
$this->setDefaults();
}
function set($tag, $value){
$this->template->assign($tag, $value);
}
function setDefaults(){
$this->template->assign('<header>', 'This is the header content');
}
}
class ConfirmView extends DefaultModuleView {
function __construct(){
parent::__construct();
}
function assignConfirmation($message) {
$this->template->assign('<content>', $message);
}
}
class MenuView extends View {
function __construct($links){
$this->template = new TemplateBuilder("defaultMenu.html");
$this->buildMenu($links);
}
function buildMenu($links)
{
foreach ($links as $link){
$menu .= $link."<br>";
}
$this->template->assign('<menu>', $menu);
}
}
abstract class BaseController{
abstract function execute();
abstract function getView();
}
class ConfirmationPageController extends BaseController {
protected $view;
function __construct(){}
function execute()
{
$menu = new MenuView(array("Link1", "Link2", "Link3", "Link4"));
$view = new ConfirmView();
$view->set('<leftMenu>', $menu->renderView() );
$view->assignConfirmation("This Worked!");
$this->view = $view;
}
function getView()
{
return $this->view;
}
}
$controller = new ConfirmationPageController();
$controller->execute();
$view = $controller->getView();
echo $view->renderView();






Bookmarks