I wanted to simplify my views and take advantage of the ClisView features (sorting, paging,...).
(I had foreach to loop on the comments lists and display the list).
To achieve this, I renderPartial my _comments view
$this->renderPartial('_comments',array(
'dataProvider'=>$dataProvider,
and in my _comments view, in order to list the comments related to a post, I use
<?php $this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_comment',
'template'=>"{items}\n{pager}",
)); ?>
the _comment view simply contains the following code
<div class="comment">
<div class="content">
<?php
$this->beginWidget('CMarkdown', array('purifyOutput'=>true));
echo $data->content;
$this->endWidget();
?>
</div>
</div>
it works fine, it displays the correct data but not in the right place.
To be clear, let say I have 2 posts , POST 1 has 3 comments and POST 2 has 2 comments.
If I click on the POST 1 link to comments, it looks correct, it displays
Post 1 - link to comments
Comment 1 (of post 1)
Comment 2 (of post 1)
Comment 3 (of post 1)
Post 2- link to comments
but if I click on the POST 2 link to comments, it displays the following
Post 1 - link to comments
Comment 1 (of post 2)
Comment 2 (of post 2)
Post 2 - link to comments
So the comments are displayed under post 1 and not post 2.
I logically expected
Post 1 - link to comments
Post 2 - link to comments
Comment 1 (of post 2)
Comment 2 (of post 2)
I must clarify that the list of posts is also displayed by a cListView and when I look to the source code the class names generated are identicals.
here is the code where the dataprovider is defined
$criteria=new CDbCriteria(array(
'condition'=>'post_id='.$post_id,
'order'=>'create_time DESC',
));
$dataProvider=new CActiveDataProvider('Comment', array(
'pagination'=>array(
'pageSize'=>Yii::app()->params['commentsPerPage'],
),
'criteria'=>$criteria,
));
$this->renderPartial('_comments',array(
'dataProvider'=>$dataProvider,
));
So my question would be, how to ask ClistView to generate different class names ?
Do you know how I can correclty display the comments ?
Thank you in advance for your help