I am starting to learn codeigniter and the whole MVC framework. What im looking to find is how to add data to the header file without having to add it to every controller.
Here is my file layout
application
--controller
--main.php
--view
--includes
--header.php
--footer.php
--template.php
--main.php
In my main.php file i have
function main() {
$data['mainView'] = "main";
$this->load->view('includes/template',$data);
}
In my template.php file
<?PHP
$this->load->view('includes/header');
$this->load->view($mainView,$data);
$this->load->view('includes/footer');
Again… what im looking for is a way to globally pass in data to the header file so I do not have to add the data to every controller i make. The type of data that i would be passing in is user data (user name, last login, messages….)
Thank you!
There are two good ways I’ve seen this done:
1. Add it to a
MY_Controllerclass, which all your related controllers extend:2. Add it to a
MY_Outputclass, which makes sense, as a full HTML page is rendered differently than, say, an AHAH partial or AJAX response:This way also has the advantage of not having to include the header/footer on each of your views, and is easier to change directions later.
Cheers!