ClistVIew Pagin issue

I am using Yii framework of php. My scenario is I’ve number of projects and all the projects have posts. For projects i used Clistview and in the ‘itemView’ of this control another page is specified named ‘_post’. In ‘_post’ page again ClistView is specified for showing post details.

But the problem is when paging occur in post details Clistview of the projects and changing the page number of the one post detail to next page number, all the post detail clistview page number changes.

I have also specified post detail clistview ‘id’ but in no vain.

This is how i finally got it working, it will work until you find a better solution.

i’m assuming that project_id is a foreign key in your posts table.

Which will generate(using gii) the necessary HAS_MANY relation in your project model, which in turn enables us to access the posts of a project easily, without calling the CallProjectPosts method.

So modify your Post view(_post.php):




<?php

echo '<h2>Project: '. CHTML::encode($data->title).' </h2>';

echo '<div class="listViewBorder">';


$relatedPosts=new CArrayDataProvider($data->posts, // this is where the HAS_MANY relation comes into play

        array(

            'pagination'=>array(

                'pageSize'=>1, // whatever your size was

            )

        )

);

$this->widget('zii.widgets.CListView',

           array(

               'dataProvider'=>$relatedPosts,

               'id'=>'postListView'.$data->id,

               'itemView'=>'_postDetail',

               'enablePagination'=>true,

           ));

echo '</div>'

?>



For Project list :




<?php

$this->pageTitle=Yii::app()->name . ' - Project Post Details';

echo '<div class="listViewBorder">';

$this->widget('zii.widgets.CListView', 

          array(

              'dataProvider'=>$dataProvider,

              'id'=>'projectListView',

              'itemView'=>'_post', // refers to the partial view

              'enablePagination'=>true,

              'ajaxUpdate'=>false

          )

);

echo '</div><br />'

?>



As you will see, i have disabled ajaxUpdate for the project list view, if it is enabled, then the solution will not work, so if your requirement is to display/update the project list also through ajax then this will not work, currently only the project posts are updated through ajax.

Hope this helps.

From my stackoverflow answer.

had to do make ajaxUpdate false for the outer clistvew, coz when the inner clistview ajax update was being called, for some reason the outer clistview update was also happening, you can see this behavior in Firebug’s console view, so i just disabled the outer view’s ajax, and then only the inner clistview’s ajax was being called. Now, i don’t think it is a bug, there has to be some method, to update only the inner view through ajax. Anyone here can help out with this?

This discussion is also happening in stackoverflow here : SO Link