Wes
Wes

Reputation: 1291

CodeIgniter: Passing variables between views

Let's say you load a view from a controller and that view loads another view that uses a lot of the same variables as the view that loaded it. How do get both views to share those variables? Thanks

Upvotes: 2

Views: 3461

Answers (3)

In one view, i set this:

window.variable= variableToAnotherView;

windows.variable is to pass the variable globaly, so you will be able to call it in another view.

Upvotes: 1

Robin Castlin
Robin Castlin

Reputation: 10996

All variables you define to a view, are passed down to views loaded within the parent one. You don't need to pass them down an other level through the second array parameter, unless you want to override a specific value.

Basically, define all variable in the 2nd parameter to the "parent" view and both views will have these variables.

Upvotes: 3

Kumar V
Kumar V

Reputation: 8830

For ex: you are loading view in controller:

$data["msg"] = "hi";
$this->load->view("view_file",$data);

In view_file, you are loading another view file

$this->load->view("view_file2",array("msg"=>$msg)); // here msg is extracted from first view file

Upvotes: 1

Related Questions