1

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

tereško
  • 58,060
  • 25
  • 98
  • 150
Wes
  • 1,183
  • 3
  • 23
  • 51

3 Answers3

3

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.

Robin Castlin
  • 10,956
  • 1
  • 28
  • 44
1

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
Kumar V
  • 8,810
  • 9
  • 39
  • 58
1

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.