[eluser]luben[/eluser]
Hello, I'm new to the Code Igniter framework and I look at it for a couple of days. From what I saw, I can tell it's great, intuitive and easy to use.
The problem I want to present is common:
I do not want to include the HEADER, SIDEBAR and FOOTER views manually in all controllers and methods.
That's why I looked at the Template Library created by one of the forum members here.
However, I cannot get the sense and advantages of it. My question is, what am I missing?
Here is example of my confusion:
Case 1: Normal usage without Template Library
Code:
function index()
{
$data = 'some header data';
$this->load->view('global/header', $data);
$data = 'some content data';
$this->load->view('current-page-view', $data);
$data = 'some footer data';
$this->load->view('global/footer', $data);
}
function another()
{
$data = 'other header data';
$this->load->view('global/header', $data);
$data = 'other content data';
$this->load->view('current-page-view', $data);
$data = 'other footer data';
$this->load->view('global/footer', $data);
}
Case 2: Usage with Template Library
Code:
function index()
{
$data = 'some header data';
$this->template->write_view('header', 'global/header', $data, TRUE);
$data = 'some content data';
$this->template->write('content', $data);
$data = 'some footer data';
$this->template->write_view('footer', 'global/footer', $data, TRUE);
$this->template->render();
}
function another()
{
$data = 'other header data';
$this->template->write_view('header', 'global/header', $data, TRUE);
$data = 'other content data';
$this->template->write('content', $data);
$data = 'other footer data';
$this->template->write_view('footer', 'global/footer', $data, TRUE);
$this->template->render();
}
The code with Template Library is even one line longer and again, I have to manually call the views I would like to include in every controller and function. I guess, I didn't get the usage of the library well, and hope to find some help in case you have found the way to use it properly.
Thank you and best regards,
luben