I am very new to CodeIgniter, but I think I have a grasp on how it works.
Typically when I make a website, like a 5-page site, I have my header file in a php file which is included in each page, so that if I have to alter the header I only have to do it in one spot rather than changing it five times.
In my CodeIgniter application, I have a function for each page in my controller which loads a different view, depending on the function. For example,
public function Index() {
$data = array();
$this->load->view('index',$data);
}
public function blog() {
$data = array();
$this->load->view('inner1',$data);
}
Then I can put all my logic in the controller.
What's the best way to have one referenced header? Should I put it in the controller as a variable and then send it as data to each view?
Also, if there's a more efficient way of doing this, please suggest it!
Thanks!
What I usually do is make the header in a view, and then add the header view to the controller above index... you can do the same with footer too.
So it would be something like:
public function blog() {
$data = array();
$this->load->view('Header'); // just the header file
$this->load->view('inner1',$data); //your main content
}
Make sense?
Added: You can also include your entire head tag in there too, like your meta tags, title, css links etc. But I usually put those in another view because sometimes they are different depending on the page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With