I’m new in Yii Framework and I would like to render the commments associated to a given post. I tried to find solution but until now, I cannot figure out how to do it.

I have a list of posts and when I click a link I want to list the associated comments without refreshing all the page.

To be clear, I have the following

Post 1

My post 1 description … Comment (1)

Post 2

My post 2 description … Comment (3)

Post 3

My post 3 description … Comment (5)

and when I click to comment (3) of the post 2, I want the following

My post 1 description … Comment (1)

Post 2

My post 2 description … Comment (3)

Comment 1

Comment 2

Comment 3

Post 3

My post 3 description … Comment (5)

Any help would be appreciate

(Pity that nobody can help!)

hello sanfisa it is simple add the following to your view if you are using list view then add this to _view.php


echo CHtml::ajaxLink('Comment(3)',$this->createUrl('post/viewComment'),array(

    'data' => array('id'=>$data->id),




<span class="comment<?php echo $data->id;?>"></span>

and in controller

public function actionViewComment()


     $id = $_GET['id'];

     //do retrieve here by the post id

    // echo the comment


here i pass the post id to the controller action via ajax and the id is available in the action and do some actions there and echo the result. the result is appeared inside the span with

<span class="comment<?php echo $data->id;?>"></span>

Thank you very much Ahamed.

Actually I use the blog application I got from Yii Framework.

in the index.php Post View I have

<?php $this->widget(‘zii.widgets.CListView’, array(




)); ?>

which list the partial view _view.php

from _view.php, I want to call the _comments.php view which list all the comments

inside _comments.php

there is a <?php foreach($comments as $comment): ?>

I would like to call this view by passing the post_id in order for this view to get the

list of comment with the given post_id

Thank in advance for your help if I don’t bother you