Öncelikle kütüphanemizi oluşturalım. CodeIgniter dizininde libraries klasöründe “TempK” isminde bir PHP dosyası oluşturalım.
TempK
class tempK {
protected $CI;
public function __construct()
{
$this->CI =& get_instance();
}
public function get($temp, $data=null)
{
$data['header'] = $this->CI->load->view('template/header',$data,true);
$data['sidebar'] = $this->CI->load->view('template/sidebar',$data,true);
$data['content'] = $this->CI->load->view('content/'.$temp,$data,true);
$data['footer'] = $this->CI->load->view('template/footer',$data,true);
$this->CI->load->view('template/index',$data);
}
}
?>
Yukarıda yer alan kodlarımızda, template klasörümüzde bulunan header.php, sidebar.php, footer.php ve content klasöründe bulunan dosya ismi dinamik olan home.php dosyamıza veri gönderelim. En alt satırda da index.php dosyamızda gösterelim.
Template
View klasörümüzün içerisine Template isminde bir klasör daha oluşturalım ve içerisinde header.php, sidebar.php, footer.php ve index.php dosyaları oluşturalım.
Footer