Welcome Guest, Not a member yet? Register   Sign In
My Template Is Not Loading Up
#1

[eluser]razerone[/eluser]
Hi I have got my own template library but is not loading up with controller here is what I have added.

system > library > template.php

Code:
<?php
class Template {
public $data = array();

public function fetch($filename) {
$file = DIR_TEMPLATE . $filename;
if (file_exists($file)) {
extract($this->data);
ob_start();
include($file);
$content = ob_get_contents();
ob_end_clean();
return $content;
} else {
trigger_error('Error: Could not load template ' . $file . '!');
exit();    
}
}
}
?>

system > core > controller.php add

Code:
protected function getChild($child, $args = array()) {
$action = new Action($child, $args);
if (file_exists($action->getFile())) {
require_once($action->getFile());
$class = $action->getClass();
$controller = new $class($this->registry);
$controller->{$action->getMethod()}($action->getArgs());  
return $controller->output;
} else {
trigger_error('Error: Could not load controller ' . $child . '!');
exit();    
}  
}

protected function render() {
foreach ($this->children as $child) {
$this->data[basename($child)] = $this->getChild($child);
}
if (file_exists(DIR_TEMPLATE . $this->template)) {
extract($this->data);  
ob_start();
require(DIR_TEMPLATE . $this->template);
$this->output = ob_get_contents();
ob_end_clean();
return $this->output;
} else {
trigger_error('Error: Could not load template ' . DIR_TEMPLATE . $this->template . '!');
exit();    
}
}

app > controllers >

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Home extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->library('template');
}

public function index() {
if (file_exists(DIR_TEMPLATE  . '/template/common/home.tpl')) {
$this->template =  '/template/common/home.tpl';
} else {
$this->template = 'default/template/common/home.tpl';
}
$this->children = array(
'common/column_left',
'common/column_right',
'common/content_top',
'common/content_bottom',
'common/footer',
'common/header'
);
$this->response->setOutput($this->render());
}
}




Theme © iAndrew 2016 - Forum software by © MyBB