![]() |
How to handle controller for every reload ? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: How to handle controller for every reload ? (/showthread.php?tid=11960) |
How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]hykoh[/eluser] How can I handle outer controller ? e.g. in every site, $this->load->view('header'); and $this->load->view('footer'); get included. I post already another thread, nearly with the same thematic ... how can I load EVERYTIME the script runs through, definied functions like a language include for the menu inside the "header" ? Or if the menu must get dynamically out of a database ? What is the best way to include some functions/controller/models at every page load ? How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]Yash[/eluser] Qs is not so clear to me..but constructor can do the trick How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]Dready[/eluser] That's a good question. You'll perhaps find utilities that do this for you (advanced templates classes, etc) in the wiki. My personnal trick is to create an helper function that I call at the end of any controller function, and that adds all the stuff. Something like : Code: // inside controller function and an helper like : Code: function render_output($main_html) { That's enough, and you have the choice not to call your helper function, for example in case of a controller method returning an AJAX response in json, or whatever. How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]hykoh[/eluser] it looks good ![]() thanks How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]SitesByJoe[/eluser] Here's the bit you are missing - your view can call other views. I usually pass the content bits within each page as an array from the controller, sort of like this: My Controller (snippet): Code: <?php My view: Code: <html> This is a very simple example at least to get the idea across. I recall having trouble absorbing this when I first started with CI. How to handle controller for every reload ? - El Forum - 09-30-2008 [eluser]meigwilym[/eluser] Here's a quick example using a simple app that I'm currently building. I've got two global views header.php and main.php. Each file has <?php echo $content; ?>. header.php is the html for the <head> and main.php has everything else. I then have more views, with 2 or 4 columns, which I can use as I want. In the controller I have Code: // load some JS first... |