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

#1
[eluser]edoornav[/eluser]
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.

~rvr

#2
[eluser]nirbhab[/eluser]
VIEW PAGE:
i think this might help u out.

<?php
echo $user_id;
?>

if it doesn't works than:

$data['dataOne']='user_id';
$data['dateTwo']=$user_id;
<?php $this->load->view('footer',$data) ?>

View page:
<?php
echo $dataOne;
echo $dateTwo;
?>

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

#3
[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.

#4
[eluser]edoornav[/eluser]
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.

~ryan

#5
[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.