Welcome Guest, Not a member yet? Register   Sign In
How to pass all view vars (not only controller data) to another nested view


please help me with this issue!


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


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!

if you use
it will be available in all sub views

Hi Dam1an,

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


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?

I am sorry but I still cannot access new variables I have defined in parent view, only have access to controller data.

Can you post your controller code

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

Why are you creating variables in the view? You should only have presentation logic in the view

Theme © iAndrew 2016 - Forum software by © MyBB