Passing in a array into a sub-view |
[eluser]msteudel[/eluser]
I have something like the following: Code: <?php $this->load->view( 'photo', array( 'iso' => $iso ) ?> In my photo view I do the following: Code: <?php var_dump( $iso ) ?> and I get: Code: Severity: Notice I also tried doing something like: Code: <?php echo $secondData['votes'] = $num_votes ?> I'm not sure why it's not allowing me to pass data into my views ...
[eluser]techgnome[/eluser]
Something I recently discovered, is that variables available to the view are also available in the sub view w/o needing to pass them again... Try loading your view like this: Code: <?php $this->load->view('photo'); ?> And use the var_dump($iso); in your photo view, see if you get a different result. -tg
[eluser]msteudel[/eluser]
That's what I thought too, but I got the undefined error, which is why I started trying to pass in the data ... I must be doing something not normal ... but I can't figure it out.
[eluser]Dennis Rasmussen[/eluser]
[quote author="techgnome" date="1286159186"]Something I recently discovered, is that variables available to the view are also available in the sub view w/o needing to pass them again...[/quote] What?? Since when? Where do you see that change? :O
[eluser]InsiteFX[/eluser]
From the userguide: Code: $this->load->vars($data); Enjoy InsiteFX
[eluser]Dennis Rasmussen[/eluser]
That is just pure love <3 If just I knew that long time ago
[eluser]InsiteFX[/eluser]
It's a little hard to find, because it is under the loader library. Loader Library But here is the link to it. InsiteFX
[eluser]techgnome[/eluser]
[quote author="Dennis Rasmussen" date="1286161413"][quote author="techgnome" date="1286159186"]Something I recently discovered, is that variables available to the view are also available in the sub view w/o needing to pass them again...[/quote] What?? Since when? Where do you see that change? :O[/quote] Discovered by accident... my controllers all load a common template, then inside the template, I load sub views. I had been passing an array to the sub-views, but was running into a problem setting them up properly. Through some accidental experimentation, I found all my variables from the main view available to me in the sub views. -tg
[eluser]Dennis Rasmussen[/eluser]
[quote author="InsiteFX" date="1286167591"]It's a little hard to find, because it is under the loader library. Loader Library But here is the link to it. InsiteFX[/quote] That explains it. I've read every bit and part of the sourcecode and userguide EXCEPT for the loader library. Talk about no luck [quote author="techgnome" date="1286187990"]Discovered by accident... my controllers all load a common template, then inside the template, I load sub views. I had been passing an array to the sub-views, but was running into a problem setting them up properly. Through some accidental experimentation, I found all my variables from the main view available to me in the sub views. -tg[/quote] Yeah I did this as well for some months, then I recently went over to loading views in the controller, but seeing it's possible to pass global view-variables, I'll head back to views + subviews (as I believe it's up to the designer to sort all of this out). All in all, great to know |
Welcome Guest, Not a member yet? Register Sign In |