[eluser]SPeed_FANat1c[/eluser]
Hi,
I am trying to do another CI project. And I had problem in first one - I made sidebar_view.php and my controllers were like this:
Code:
$this->laod->view('header_view');
$this->load->view('menu_view');
$this->load->view('something_view',$data);
$this->load->view('sidebar_view');
$this->load->view('footer_view');
I inicialy static sidebar view - did not loaded data from database. And when I wanted to change it - to load data from database. I could:
in every controler of my entire project make
Code:
$this->load->view('sidebar_view',$data);
this is a lot of work to make the same action in every controller. And I could forget to update some controller.
Don't know if it is even possible, but I guess it would be not a good practice just add code directly to the sidebar_view which loads data from database.
And another option that worked - using ajax to load content from database. This is of course bad.
The same is with header view lets say - if you want to modify, you must modify in every controller. This is so unefficient.
So when I am writing this post I started thinking, maybe I should do something like this:
make a model for sidebar. And in every controller add lines
Code:
$data = $this->sidebar_model->load_data;
$this->load->view('sidebar_view',$data);
The same do with header and footer view. Then when I want to change data in sidebar, I just modify one model and the sidebar is modified, no need to modify every controller.
How do you think about this? Or maybe there is better ways to do this?