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
5
-
@Vickel. Did you try to load view in another view?Kumar V– Kumar V2014-01-18 17:26:00 +00:00Commented Jan 18, 2014 at 17:26
-
@Vickel. No you didn't try. I have done in my projects to avoid redundancy, we make a single file and loaded in another view file too.Kumar V– Kumar V2014-01-18 17:29:38 +00:00Commented Jan 18, 2014 at 17:29
-
@kumar_v now I'm learning... can you please post an example?Vickel– Vickel2014-01-18 17:31:43 +00:00Commented Jan 18, 2014 at 17:31
-
@Vickel stackoverflow.com/questions/9402924/…Kumar V– Kumar V2014-01-18 17:34:25 +00:00Commented Jan 18, 2014 at 17:34
-
2I've just tried it out, you're right, it works! thanks for letting me know something new, very helpful, indeedVickel– Vickel2014-01-18 17:36:05 +00:00Commented Jan 18, 2014 at 17:36
Add a comment
|
3 Answers
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.
Comments
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