Dataprovider Not Paging

Dear all,

I follow this site


http://www.dukaweb.net/2013/11/pagination-with-cactivedataprovider-yii.html

for paging model, but it can not work, hope you help me for this solution.

Controller:


$model = News::model()->findAll();

		//pagin view

 		$dataProvider=new CActiveDataProvider(array(

                        'pagination'=>array(

                                'pageSize'=>10,

                        ),

                        'models'=>$model,

                ));	

view:


<?php 

 	$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'enablePagination' => true,    

));

 ?>

thankyou very much

pass your name of the model as first argument to CActiveDataProvider and then pass array of configurations like this


$dataProvider = new CActiveDataProvider ( 'News',array(

'pagination' =>array (

'pageSize' =>10 ,

),

));


$this->render('gridview',array('dataProvider'=>$dataProvider));



(no need to create model and no need to use findAll() method.) just pass the dataProvider to the view

yes it work fine, but in the other scenario, how we paging for this table ? here is my code.

Controller:


public function actionLanguage($lang){

		Yii::app()->setLanguage($lang);

		$model = News::model()->findAll();	

		$this->render('index',array(

			'models'=>$model,

		));	

		

	}



View:


<table>

	<tr>

		<th>No</th>

		<th><?php echo Yii::t("app","title");?> </th>

		<th><?php echo Yii::t("app","image");?> </th>

		<th><?php echo Yii::t("app","enShortContent");?></th>

		<th><?php echo Yii::t("app","vnShortContent");?></th>

		<th><?php echo Yii::t("app","active");?></th>

		<th></th>

	</tr>

	

<?php if($models != null): ?>

	<?php $num = 0 ?>

    <?php foreach($models as $model): ?>

    <tr>

    	<td><?php echo $num = $num +1?></td>

    	<td><?php echo $model->title; ?></td>

    	<td><img src="protected/upload/<?php echo $model->images;?>" width="100" height="100"/></td>

    	<td><?php echo $model->en_shortDescription; ?></td>

    	<td><?php echo $model->vn_shortDescription; ?></td> 

    	<td><?php echo $model->active; ?></td>

    	<td><?php echo CHtml::link(Yii::t("app","detail"),array('news/detail',

                                     'id'=> $model->idnews)); ?>

                                     &nbsp;|&nbsp;

            <?php echo CHtml::link(Yii::t("app","edit"),array('news/edit',

                                     'id'=> $model->idnews)); ?>

                                      &nbsp;|&nbsp;

           <?php echo CHtml::link(Yii::t("app","delete"),array('news/delete',

                                     'id'=> $model->idnews)); ?>

      </td>

    </tr>

    <?php endforeach; ?>


<?php endif; ?>

</table>



you can use the same way you did previously in your action and but in your view use like this




foreach($dataProvider->getData() as $data)

{

echo $data->column;

}



and use CLinkPager widget for pagination

the return of $dataProvider have 13 elements, but the view just display 5 elements and it has not the paging,

controller


$dataProvider = new CActiveDataProvider ( 'News',array(

							'pagination' =>array (

							'pageSize' =>5,

							),

							));


		var_dump($dataProvider);die;					

		$this->render('index',array('dataProvider'=>$dataProvider));

View:


<table>

	<tr>

		<th>No</th>

		<th><?php echo Yii::t("app","title");?> </th>

		<th><?php echo Yii::t("app","image");?> </th>

		<th><?php echo Yii::t("app","enShortContent");?></th>

		<th><?php echo Yii::t("app","vnShortContent");?></th>

		<th><?php echo Yii::t("app","active");?></th>

		<th></th>

	</tr>

	

<?php if($dataProvider != null): ?>

	<?php $num = 0 ?>

    <?php foreach($dataProvider->getData() as $data): ?>

    <tr>

    	<td><?php echo $num = $num +1?></td>

    	<td><?php echo $data->title; ?></td>

    	<td><img src="protected/upload/<?php echo $data->images;?>" width="100" height="100"/></td>

    	<td><?php echo $data->en_shortDescription; ?></td>

    	<td><?php echo $data->vn_shortDescription; ?></td> 

    	<td><?php echo $data->active; ?></td>

    	<td><?php echo CHtml::link(Yii::t("app","detail"),array('news/detail',

                                     'id'=> $data->idnews)); ?>

                                     &nbsp;|&nbsp;

            <?php echo CHtml::link(Yii::t("app","edit"),array('news/edit',

                                     'id'=> $data->idnews)); ?>

                                      &nbsp;|&nbsp;

           <?php echo CHtml::link(Yii::t("app","delete"),array('news/delete',

                                     'id'=> $data->idnews)); ?>

      </td>

    </tr>

    <?php endforeach; ?>


<?php endif; ?>

</table>

you are setting the page size to 5 so it displays only 5 results. and by setting the pageSize does not display any paginations only the clistview, cgridview can show pagination automatically. if you are using your own you have to create pagination.

read this post I hope it helps you.

you are setting the page size to 5 so it displays only 5 results. and by setting the pageSize does not display any paginations only the clistview, cgridview can show pagination automatically. if you are using your own you have to create pagination.

read this post I hope it helps you.