MVC Help with templating
Posted: Sun Apr 19, 2009 9:05 pm
Hey guys, I've recently gone through a tutorial for building a MVC from the ground up... and I have everything up and running!
tutorial can be found at (http://anantgarg.com/2009/03/13/write-y ... rk-part-1/).
This has it setup to have a template setup for the views and or default controller... Im trying to setup a master template that would surround all of that?
The code is as follows for template.class.php:
any help or pointing in the right direction would be greatly appreciated. and just so i dont <span style='color:blue' title='I'm naughty, are you naughty?'>smurf</span> anyone off... i have googled this for about 3 hours now with no luck?
Thanks!
tutorial can be found at (http://anantgarg.com/2009/03/13/write-y ... rk-part-1/).
This has it setup to have a template setup for the views and or default controller... Im trying to setup a master template that would surround all of that?
The code is as follows for template.class.php:
Code: Select all
<?php
class Template {
protected $variables = array();
protected $_controller;
protected $_action;
function __construct($controller,$action) {
$this->_controller = $controller;
$this->_action = $action;
}
/** Set Variables **/
function set($name,$value) {
$this->variables[$name] = $value;
}
/** Display Template **/
function render() {
extract($this->variables);
if (file_exists(ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'header.php')) {
include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'header.php');
} else {
include (ROOT . DS . 'application' . DS . 'views' . DS . 'header.php');
}
include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . $this->_action . '.php');
if (file_exists(ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'footer.php')) {
include (ROOT . DS . 'application' . DS . 'views' . DS . $this->_controller . DS . 'footer.php');
} else {
include (ROOT . DS . 'application' . DS . 'views' . DS . 'footer.php');
}
}
}
Thanks!