Welcome Guest, Not a member yet? Register   Sign In
Nested views within for loops
#1

[eluser]TheBenno[/eluser]
I have read a lot of different solutions for nesting views in CodeIgniter, but all of the solutions I've found (and use) really only work for single-items. For example: you nest your "content" view inside your "wrapper" view where the wrapper contains the common header and footer, and basically just has a variable in the heart of it called $content, which gets filled with the string returned from a call to load->view.

Instead, my problem is that I want to nest a view MANY times, specifically within a for loop. Here is a simple example:


Code:
<?foreach($things as $thing):?>
    /*This stuff in here is in its own view.
      How do i conveniently load a view with
      $thing as the data for that view?*/
<?endforeach;?>

Does anyone have any ideas on how best to solve this?

Thanks!
TheBenno
#2

[eluser]rbnc[/eluser]
Code:
<?php foreach($things as $thing):?>
     <?php $this->load-view('thing.php',array('thing'=>$thing)); ?>
<?php endforeach;?>
#3

[eluser]TheBenno[/eluser]
Holy crap!! I had no idea that worked. Thanks so much rbnc, this really impresses me! Well done CodeIgniter!




Theme © iAndrew 2016 - Forum software by © MyBB