Welcome Guest, Not a member yet? Register   Sign In
load the same content into the sidebar from every controller?
#1

[eluser]crispyhihats[/eluser]
Maybe I have my views setup incorrectly or i'm not fully understanding this.. but..

I have a template/main.php file which loads template/header.php template/footer.php and the body, which is whatever controller view is being requested.

I also call the sidebar as well.. My problem is getting the same content for the sidebar to display on every view. Currently, I can set a variable inside a specific controller and have it display in the sidebar when I go to that view...however I would need to add that variable to every single controller to get that data to stay consistent.

This is probably very confusing because i'm confusing myself... but how do I load dynamic content from the model into the sidebar without the need of setting a variable in every single controller?


template/main.php : http://i.imgur.com/61sYjH6.png
template/skeleton.php : http://i.imgur.com/D5l3hrA.png
MY_Controller.php : http://i.imgur.com/rsEwGUR.png
#2

[eluser]crispyhihats[/eluser]
this is the code i'm using :

http://arjun.net.in/base-controller-codeigniter/


is there a better way to go about this? I need the sidebar to have the same content for most pages, but certain pages should have different content.. looking for the easiest way to load content without the 100's of extra lines of code it will take if I have to use $this->data['some_side_bar_variable'] = $this->model->my_sidebar_thing(); in every controller.
#3

[eluser]InsiteFX[/eluser]
If you need data in all your views you can do this:
Code:
$data = array();

$data['sidebar'] = 'some text';

$this->load->vars($data);  // global to all views now!
$this->load->view('my_view');  // do not pass $data to it or you could create a nother $data and pass it

You can use $this->load->vars($code); in any place you want.
#4

[eluser]crispyhihats[/eluser]
[quote author="InsiteFX" date="1393684579"]If you need data in all your views you can do this:
Code:
$data = array();

$data['sidebar'] = 'some text';

$this->load->vars($data);  // global to all views now!
$this->load->view('my_view');  // do not pass $data to it or you could create a nother $data and pass it

You can use $this->load->vars($code); in any place you want.
[/quote]

thank you for the response! While researching, I came across $this->load->vars ... It doesn't seem to work for me though.

using your code example above, I am able to use $sidebar on the view that is loaded by the controller that has $this->load->vars but not in any other view. Do you think this could be because of the way i'm templating?
#5

[eluser]InsiteFX[/eluser]
Yes or you have something else wrong in your code some place.




Theme © iAndrew 2016 - Forum software by © MyBB