![]() |
Including a file - 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: Including a file (/showthread.php?tid=34782) |
Including a file - El Forum - 10-09-2010 [eluser]sahanlak[/eluser] Does codeigniter have any functions for file including? I have a file that shows a sidebar through out the entire site, it has some database results showing so I was hoping to include it to pages. I don't like to do this from load->view since it breaks the mvc pattern (don't know if its possible ![]() Including a file - El Forum - 10-09-2010 [eluser]ram4nd[/eluser] use helper or library Including a file - El Forum - 10-09-2010 [eluser]cahva[/eluser] The best would be to use base controller which you can use to set things up. Heres a little tutorial how to use base controllers: http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY Heres an overly simplified example: Front_controller (base controller that you will extend from in your normal controllers) Code: class Front_controller extends Controller { Somepage controller: Code: class Somepage extends Front_controller { View for layout Code: <div id="sidebar"> EDIT: Had some errors in $this->load->view. Forgot to use the third parameter TRUE to returns the view. Fixed now. Including a file - El Forum - 10-09-2010 [eluser]sahanlak[/eluser] [quote author="cahva" date="1286657542"]The best would be to use base controller which you can use to set things up. Heres a little tutorial how to use base controllers: http://philsturgeon.co.uk/news/2010/02/CodeIgniter-Base-Classes-Keeping-it-DRY Heres an overly simplified example: Front_controller (base controller that you will extend from in your normal controllers) Code: class Front_controller extends Controller { Somepage controller: Code: class Somepage extends Front_controller { View for somepage Code: <div id="sidebar"> Thanks a lot ![]() Including a file - El Forum - 10-09-2010 [eluser]cahva[/eluser] Corrected some errors in my code. The last view was for the "layout", not "somepage". Also didnt return data with load->view with the partials. Corrected now. |