• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
passing data to "sub-templates"

Has anyone managed to pass data to sub-templates loaded from within a template? Like, inside your page view:

<?php $this->load->view('footer', array('user_id', $user_id)) ?>

I don’t seem to be having any luck. Thanks.


i think this might help u out.

echo $user_id;

if it doesn't works than:

<?php $this->load->view('footer',$data) ?>

View page:
echo $dataOne;
echo $dateTwo;

I am working on this type of data passing to the template.

[eluser]Armchair Samurai[/eluser]
Embedding views within views

It's amazing what you can come up with when you use the search function. Tongue

Alternately, various people have implemented templating systems which take care of things like this.

Why do I need to search when I've got you, Armchair Samurai? Smile

Oops, it actually works fine if I correct my mistake (comma instead of =>):

<?php $this->load->view('footer', array('user_id' => $user_id)) ?>

[sheepishly] My bad.


[eluser]Phil Sturgeon[/eluser]
Thats a slightly dirty method of using code in views, you should try to limit that sort of thing and prepair as much as you can in the controller. Of course in this example its not really important, but i'd be tempted to assign the contents of that view to a variable in the controller, then output that variable in your view.

That way you share the same data variable, and have less dirt h4x in your view.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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