• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Architecture Header - Body - Footer

#1
[eluser]DCZ[/eluser]
Hey everybody !

I want to bounce an idea to see what other people think and if they have better solutions.

Since my header and footer are the same on every page I would like to add them as simple as possible to every page.

I used to have code like this :

--> load_header();
--> load_body (arg[]);
--> load_footer();
--> print_to_screen();

And the load_body would call a differnt page depending on the url parameters.
So I would only have to load my header and footer only once.

Now I would like to start using CI.
So in order to have the same result I've created a MY_Controller that extends the controller class. Inside I have 2 functions "load_header" and "load_footer".
Every new page extends MY_Controller, but I still have to call on every page "load_header", "load_footer" in order to print my header and footer.

So now I was wondering if there wasn't a better way ?

Greetz

#2
[eluser]Dam1an[/eluser]
The way I do it, is to have a render function in MY_Controller
This loads the default header and footer and specified body view

You then just have to call render at the end of your functions (I've got around this using a post controller hook, but don't want to complicate things for you just yet)

#3
[eluser]xwero[/eluser]
The simplest solution is to use a post_controller hook where you load the base template.
Code:
// hook function (basic)
function render()
{
   $this->load->view('layout');
}
// example controller method
function page()
{
    // get everything you need to display
    $this->load->vars(array('content'=>$this->load->view('page',$data)));
}
The layout view echos the content variable and has the basic markup code. This is the essential code you can make it as complex as you want.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.