Welcome Guest, Not a member yet? Register   Sign In
Page headers and footers, is this OK?
#1

[eluser]digitalbloke[/eluser]
Hi (again!)

I was reading over some of the ways to generate headers and footers with CI. I also looked at the template class:
http://williamsconcepts.com/ci/codeignit.../template/
along with a few others and then I came up with this. I just wanted to check if it is technical correct...

I have a library like so:
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Template extends Controller {

    function Template()
    {
        parent::Controller();
    }
    
    function header($title)
    {
        $data['title'] = $title;
        $this->load->view('page_header', $data);
    }
    
    function footer()
    {
        $this->load->view('page_footer');
    }
}

And I call it from my controllers like so:
Code:
<?php

class Main extends Controller
{
    function Main()
    {
        parent::Controller();
    }
    
    function index()
    {
        $this->load->library('template');
        
        $this->template->header('welcome');
        $this->load->view('home_view');
        $this->template->footer();
    }
}

Thanks, still new to all this Smile
#2

[eluser]Shay Falador[/eluser]
Hmm first thing to do is to change the 'Template' class from a controller to a library or a model. It is not a controller.
I personally prefer using a single view file, which calls other view files by the arguments it receives, if necessary.

Good luck Smile
#3

[eluser]digitalbloke[/eluser]
Hi Shay!

Thanks for your reply. Extending Controller was the only way I could find to be able to call $this->load->view();




Theme © iAndrew 2016 - Forum software by © MyBB