I have a function that I'd like plug a view file. It's pretty simple when you just need to echo
one or two things but I have some complicated html and so would like to take advantage of alternate php syntax for the following foreach loop and if statements:
UPDATE I corrected the CI->load->view
to include the 3rd parameter according to tpaksu's suggestion. It's closer to working but still not quite right. See comments below in the code:
<?
function displayComments(array $comments, $parentId = null) {
$CI=& get_instance();
foreach($comments as $comment){
if($comment['replied_to_id'] == $parentId){
echo $CI->load->view('reviews/comment_list', $comments, true); // this doesn't work, it only shows the last array member
// echo $comment['comment']; this works as expected
}
}
}
displayComments($comments, $parentId = null);
?>
Here's what the 'reviews/comment list view file looks like in its simplest form:
<ul>
<? foreach($comments as $comment): $comment=$comment['comment']?>
<li>
<?echo $comment?>
</li>
<?endforeach;>
</ul>
Would anyone know to how embed view files into a function?