<?php
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function loadHeader($data = Array(),$customHeader = 'parts/header'){
$this->load->view($customHeader,$data);
}
public function loadFooter($data = Array(),$customFooter = 'parts/footer'){
$this->load->view($customFooter,$data);
}
public function loadSidebar($data = Array(),$customSidebar = 'parts/sidebar'){
$this->load->view($customSidebar,$data);
}
}
class Articles extends MY_Controller {
public function __construct() {
parent::__construct();
}
/**
* Controller for all news.
* will be used as home controller.
*/
public function index() {
//Needed helper
//End helper
$data = Array();
//Fill the array for the header part
$data["header"] = Array();
$data["header"]["title"] = "Articles shelf";
$data["header"]["logo"] = "David Francoeur";
$data["header"]["slogan"] = "just a blog about me and knowledge...";
$this->loadHeader($data["header"]);// I would add a second parameter for a custom header.
//Fill the array for the rest of the pages
$data["main"] = Array();
$this->load->model('Article');
$data["main"]["query"] = $this->Article->get_last_ten_entries();
$this->load->view('article', $data["main"]);
//Fill the array for the right sidebar
$data["sidebar"] = Array();
$this->loadSidebar($data["sidebar"]);
//Fill the array for data concerning the footer
$data["footer"] = Array();
$this->loadFooter($data["footer"]);//I would add a second parameter for a custom footer.
}
}
//Then from my controller I do something like this :
class Articles extends MY_Controller {
public function __construct() {
parent::__construct();
}
/**
* Controller for all news.
* will be used as home controller.
*/
public function index() {
//Needed helper
//End helper
$data = Array();
//Fill the array for the header part
$data["header"] = Array();
$data["header"]["title"] = "Articles shelf";
$data["header"]["logo"] = "David Francoeur";
$data["header"]["slogan"] = "just a blog about me and knowledge...";
$this->loadHeader($data["header"]);// I would add a second parameter for a custom header.
//Fill the array for the rest of the pages
$data["main"] = Array();
$this->load->model('Article');
$data["main"]["query"] = $this->Article->get_last_ten_entries();
$this->load->view('article', $data["main"]);
//Fill the array for the right sidebar
$data["sidebar"] = Array();
$this->loadSidebar($data["sidebar"]);
//Fill the array for data concerning the footer
$data["footer"] = Array();
$this->loadFooter($data["footer"]);//I would add a second parameter for a custom footer.
}
}
//You could also use a single function in your custom controller
//if you don't need custom header or footer something like :
class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
}
public function loadView($data = Array(),$view){
$this->load->view("header_final");
$this->load->view($view,$data);
$this->load->view("footer-final");
}
}
?>
No comments:
Post a Comment