CodeIgniter:在视图之间传递变量

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

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.

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

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.