Welcome Guest, Not a member yet? Register   Sign In
Header & footer to all of the pages
#1

[eluser]Fr3aked0ut[/eluser]
Hi. I am using couple of methods (e.g post, index, page) and for each one I've got to write the same codes to add the header & the footer.
I want to know how I can write the codes only once and it will show up in all of the methods.

Thanks in advance.
#2

[eluser]fraserk[/eluser]
You can use a one of the many template systems.
Take a look at this. http://codeigniter.com/wiki/Category:App...very_page/
#3

[eluser]jedd[/eluser]
[quote author="Fr3aked0ut" date="1263754007"]
I am using couple of methods (e.g post, index, page) and for each one I've got to write the same codes to add the header & the footer.
[/quote]

fraserk is on the money here.

If you read the [url="/wiki/FAQ"]FAQ[/url] you'll find this question is asked and answered there, with pointers to a few other resources through-out the wiki. The forums - if you search for 'header footer', will in turn reveal very many threads on this already - many (in the past 12 months) contain a response by me that will read very much like this one.
#4

[eluser]Fr3aked0ut[/eluser]
OK so im using Chuck Son's take:
http://codeigniter.com/wiki/Chuck_Son's_take/
Now, this is my hook (config):
Code:
$hook['pre_controller'] = array(
                      'class'  => 'Template',
                      'function' => 'header',
                      'filename' => 'template.php',
                      'filepath' => 'hooks'
                      );
$hook['post_controller'] = array(
                      'class'  => 'Template',
                      'function' => 'footer',
                      'filename' => 'template.php',
                      'filepath' => 'hooks'
                      );

And this is template.php:
Code:
<?php

class Template extends Controller {
      function Template() {
        parent::Controller();
        $this->load->helper('url');
        $this->load->helper('html');
        $this->load->database();
      }
        
    function header()
    {
//code...
        $this->load->view('header');
    }
      function footer() {
          $this->load->view('footer');
      }
}

?>
When I get into my site, this error is displayed:
Quote:Fatal error: Call to a member function _assign_libraries() on a non-object in /system/libraries/Loader.php on line 1059
#5

[eluser]jedd[/eluser]
[quote author="Fr3aked0ut" date="1263773578"]OK so im using Chuck Son's take:
http://codeigniter.com/wiki/Chuck_Son's_take/
[/quote]

Wow - I hadn't even noticed ChuckSon had added a take.

Having a very quick read through it now, my initial impression is that this approach blows goats.

I'd suggest you read mine first, even if you later decide to go with hooks rather than MY_Controller it will give you some good insights.

Plus mine uses more colours.
#6

[eluser]Fr3aked0ut[/eluser]
Yours is too complicated.. Chuck Son's is couple of rows Big Grin
#7

[eluser]Dyllon[/eluser]
[quote author="Fr3aked0ut" date="1263777106"]Yours is too complicated.. Chuck Son's is couple of rows Big Grin[/quote]

Extending the controller is simple and offers a lot of flexibility beyond view partials, it's also a very common practice.
You may as well learn now and start doing it or you'll be kicking yourself when you realize it was the right approach in the near future.
#8

[eluser]Fr3aked0ut[/eluser]
I've made it! It is awesome! jedd, well done, thank you so much.




Theme © iAndrew 2016 - Forum software by © MyBB