scottybwoy Posted December 1, 2008 Share Posted December 1, 2008 Hi all, I'm working with with this basic framework tutorial but try as I might, I can't seem to get the templating system working properly. I'm only trying the basics first. Here's what I have. Initialisation page : <?php require_once 'central.php'; class Page extends SystemBase { function init() { $this->page->set('title', 'I Say Union, You Say Onion'); $this->page->set("right_bar", include_once(LOGIN_PAGE)); } } $p = new Page(); ?> This calls the base class, this is just the constructor and the print function : <?php class SystemBase { /*Local Atributes**********************************************/ var $db = null; // pointer to DB object var $user = null; // pointer to user object var $page = null; // pointer to a page template var $form = null; // pointer to form object var $template = ''; // path to page template /*Constructor/Destructor***************************************/ function __construct($template='home.php') { //prevent instantionation of this class (force abstract) if (!is_subclass_of($this,'SystemBase')) { trigger_error('Base instantiation from non subclass',E_USER_ERROR); return NULL; } //initialize attributes if (!defined('NO_DB')) { $this->db = new db(); $this->user = new User($this->db); } $this->page = new Template(TEMPLATE_PATH); $this->template = $template; //run the page using abstract methods $this->init(); $this->authenticate(); if (!is_null($this->form)) { $this->handleFormEvents(); } if (!defined('NO_PRINT')) { $this->printPage(); } $this->destroy(); } function printPage() { //abstract if (!is_null($this->form)) { $forms = $this->form; foreach ($forms as $form => $v) { $content = $forms->$form->DisplayForm(); $this->page->set($form, $content); } } echo $this->page->fetch($this->template); } } ?> And finally the template class, just the two main methods I'm using : <?php class Template { var $vars; // Holds all the template variables var $path; // Path to the templates function __construct($path = null) { $this->path = $path; $this->vars = array(); } function set($name, $value) { $this->vars[$name] = $value; } function fetch($file) { extract($this->vars); // Extract the vars to local namespace ob_start(); // Start output buffering include($this->path . $file); // Include the file $contents = ob_get_contents(); // Get the contents of the buffer ob_end_clean(); // End buffering and discard return $contents; // Return the contents } } ?> In my home.php template I have a placeholder <?=$right_bar?>. And want the login script to go in there, but it doesn't want to. What I have on my screen instead is the login.php script followed by the home.php page, without any of the placeholders replaced. Can anyone see why that is? Is the systemBase class __constructor written wrong and should not call the the printPage method unless no page is set? Hope this makes sense, thanks. Link to comment https://forums.phpfreaks.com/topic/135020-trying-to-get-this-template-engine-working-properly/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.