[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"><?php echo $c->author; ?></div>
<div class="message"><?php echo $c->message; ?></div>
<div class="date"><?php echo $c->date; ?></div>
<?php } ?>
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:
<?php foreach($comments as $c) {
$this->load->view('comment_view', $c);
} ?>
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