How to pass all view vars (not only controller data) to another nested view

#1
[eluser]niverin[/eluser]
Hi,

please help me with this issue!

Example:

main_view.php
Code:
$some_var = "asdlkj";
$next_var = "yxclkjasd";
$another_var = "yxlckj";
//...and many other vars, maybe I will add some or remove...

$this->load->view("nested_view");

What I want is to access all parent view variables (not only controller data) in nested_view.php without manually putting them all to $data[] (don't want to change preceding code and look for all variables that are necessary to pass).

So my question - is it possible to automatically create an array of all this view variables to pass it?

The only method that works for me is to use include(), but you understand I would like to avoid this.


Thanks for help!

#2
[eluser]Dam1an[/eluser]
if you use
Code:
$this->load->vars($data);
it will be available in all sub views

#3
[eluser]niverin[/eluser]
Hi Dam1an,

this method returns NULL for me.
Can you please describe how to use load->vars to solve my first post example?

Thanks!

#4
[eluser]Dam1an[/eluser]
You can read more about it in the user guide

You call it in the controller function instead of passing $data as the second parameter to your view just before you load the views.... make sense?

#5
[eluser]niverin[/eluser]
I am sorry but I still cannot access new variables I have defined in parent view, only have access to controller data.
:-(

#6
[eluser]Dam1an[/eluser]
Can you post your controller code

#7
[eluser]niverin[/eluser]
User guide says load->vars is good for sharing variables defined in controller but this is not my case - I need to automatically pass new variables created in view to nested view - and load->vars cannot help me with it I think(or am I wrong?).
Actually I have decided to give this effort up because can't spend whole day with solving this issue and have also headache from it Smile
I will process controller's data in all nested views again when need this vars (so I will create these vars again) or process them in controller and put vars to view data.

Thank you again for your interest in helping me

#8
[eluser]Dam1an[/eluser]
Why are you creating variables in the view? You should only have presentation logic in the view


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.