CodeIgniter Forums

Full Version: How to pass all view vars (not only controller data) to another nested view
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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!

El Forum

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

El Forum

[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!

El Forum

[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?

El Forum

[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.
:-(

El Forum

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

El Forum

[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

El Forum

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