Im trying to create my second web application in CodeIgniter.
In my previous project I created views for page header, footer and sidebar.
In every page controller I had to load these views like this:
class Home extends CI_Controller {
public function index()
{
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('home'); // home
$this->load->view('footer');
}
public function about()
{
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('about'); // about
$this->load->view('footer');
}
public function contact()
{
$this->load->view('header');
$this->load->view('sidebar');
$this->load->view('contact'); // contact
$this->load->view('footer');
}
}
I don't like this and I feel im doing it wrong.
Any suggestions?
Best Answer
in advance, you can through this way to build your view:
first create an Template in your view folder
second create an library to load your view automaticaly
third load your library in every controller constructor and then use this lib to load you view automatically
to load additional js in your view you can use
addJS
method in this way:for Css:
and to show your page content call your view file with
show
methodi hope this codes help you