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?
Asked
Active
Viewed 47 times
0
-
You can achieve this by creating a MY_Controller that extends CI_Controller, see my answer here: http://stackoverflow.com/questions/16171046/data-available-for-all-views-in-codeigniter/16171508#16171508 – Mudshark Dec 08 '14 at 14:34
-
I succeeded. Thank you! – yehuda4e Dec 08 '14 at 15:23
-
You're welcome! Please consider upvoting the original answer I linked to above :-) – Mudshark Dec 08 '14 at 15:25
-
I dont have enough reputation.. :( – yehuda4e Dec 08 '14 at 19:44
1 Answers
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