Here is the actual code for the following pseudocode:
<?php
function print_comments( $topic_id, $parent_id ) {
$all_comments = Comment::find()
->where(
'topic_id' => $topic_id,
'parent_id' => $parent_id
)->all();
if( empty($all_comment) ) {
return "";
}
$comments = '<ul>';
foreach( $all_comments as $comment ) {
$comments .= '<li>
<p> '.$comment->user_comment.' </p>
<p> by: '.$comment->byy.' </p>';
$comments .= print_comments( $topic_id, $comment->comment_id );
$comments .= '</li>';
}
$comments .= '</ul>';
return $comments;
}
?>
Put the above code at the top of your view file. Now use the following line in which you want to display / echo your comments and answers.
<?php echo print_comments( Yii::$app->getRequest()->getQueryParam('id'), 0); ?>
(previous answer)
You can try to follow this pseudocode:
print_comments( queryParam(id), 0);
print_comments ( $topic_id, $parent_id ) {
$all_comments = Comment::find()
->where(
topic_id => $topic_id,
parent_id => $parent_id
)->all();
if( $all_comment count = zero )
return
<ul>
foreach( $all_comments as $comment ) {
<li>
<p> $comment->user_comment </p>
<p> by: $comment->byy </p>
print_comments( $topic_id, $comment->comment_id );
</li>
}
</ul>
}
: .
: .
, .