dsxay48646 2014-02-10 19:13
浏览 32

ClistView Yii定位

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}
{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

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥100 支付宝网页转账系统不识别账号
    • ¥15 基于单片机的靶位控制系统
    • ¥15 AT89C51控制8位八段数码管显示时钟。
    • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题