Including a file |
[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 ) What should I do? Create a single page for a sidebar within a controller and include it?
[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/C...ing-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.
[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/C...ing-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
[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. |
Welcome Guest, Not a member yet? Register Sign In |