Welcome Guest, Not a member yet? Register   Sign In
passing variables from view to view
#1

[eluser]kmunky[/eluser]
considering that i have:

views/page.php
Code:
$this->load->view("header");
$this->load->view($main_page);//variable passed from controller
$this->load->view("footer");

controllers/show.php
Code:
$this->load->view("page",$data);//$data contains the main_page title

and in my header view i have to pass a variable containing some categories(the site menu) to be listed. What is the correct way to accomplish this? thanks
#2

[eluser]JoostV[/eluser]
Same as with all other views.

controllers/show.php
Code:
$data['menu'] = array('home' => '/', 'contact', => 'contact/form');
$this->load->view('page', $data);

views/hesader.php
Code:
echo ul($menu);
#3

[eluser]kmunky[/eluser]
so easy Tongue thanks Smile one more question though, my site menu will be needed each time when i load a view so..how can i pass that variable(containing my menu) programatically without passing it each time when i load a view?
#4

[eluser]JoostV[/eluser]
Store a base controller that you name MY_Controller in application/libraries and extend that instead of controller. Load the menu in your base controller. You will find a lot on MY_Controller on this forum.
#5

[eluser]cahva[/eluser]
I suggest you read this great post from Phil Sturgeon on the subject of MY_Controller:
http://philsturgeon.co.uk/news/2010/02/C...ing-it-DRY
#6

[eluser]kmunky[/eluser]
thanks guys, it was a real help Smile great article @cahva




Theme © iAndrew 2016 - Forum software by © MyBB