0

I use Codeigniter Framework, and I set my program to load header and footer by default when i load the view method. In the header file I have properties like: site name, description etc.. Those proprieties fetch from the DB. Now the problem is that I need to set them every time I call the view method. How can I set them by default correctly?

Sandesh
  • 1,190
  • 3
  • 23
  • 41
yehuda4e
  • 1
  • 4

1 Answers1

0

As someone said above, you should extend the Controller. I do something very simular to this, and this is my code, which is found on "MY_Controller.php" within the ./application/core directory.

public function show_view($view, $data = array())
{
    // Database connection here
    // add anything to the $data array

    $this->load->view('header', $data);
    $this->load->view($view, $data);
    $this->load->view('footer', $data);
}

Now, instead of loading a view from the controller like this;

$this->load->view('view', $data);

I do this;

$this->show_view('view', $data);

FYI. I call the function "show_view" to avoid name conflicts.

Craig
  • 1,823
  • 1
  • 11
  • 12