• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Looping through views

#1
[eluser]Unknown[/eluser]
Hi, I'm building a simple webapp using CI and I've come to a question about best practices and performance when loading views.

Let's say I want to loop through all the comments for an article, I'd normally do something like this in my view file:

Code:
<?php foreach($comments as $c) { ?>
  <div class="author">&lt;?php echo $c->author; ?&gt;</div>
  <div class="message">&lt;?php echo $c->message; ?&gt;</div>
  <div class="date">&lt;?php echo $c->date; ?&gt;</div>
&lt;?php } ?&gt;

Now, I'll probably have a much more complex code for each of the comments, so I wold like to abstract that piece of the code into another view file, and do something like this instead:

Code:
&lt;?php foreach($comments as $c) {
  $this->load->view('comment_view', $c);
} ?&gt;

But is it a good practice to load views in a loop? Maybe I can call a library method or a helper function instead?

I hope someone can help me with this.

Thank you!
Maxi


Messages In This Thread
Looping through views - by El Forum - 06-04-2012, 07:56 AM
Looping through views - by El Forum - 06-04-2012, 08:58 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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