Dear All,
I am trying to use yiinfinite-scroll extension for my project and using DAO layer . Below is my code
Controller
public function actionIndex(){
$help=new Help();
$totalCount=$help->getHelpCount();
if($totalCount < 25)
$pageSize=$totalCount+0;
else
$pageSize=25;
$criteria = new CDbCriteria;
$pages = new CPagination($totalCount);
$pages->pageSize = $pageSize;
$pages->applyLimit($criteria);
$list= $help->listHelp($criteria->limit,$criteria->offset);
$this->render('index',array("helps"=>$list,"pages"=>$pages));
}
DAO code
public function listHelp($limit,$offset){
$connection = Yii::app()->db;
$sql='SELECT h.subject FROM tbl_help h WHERE LIMIT :limit OFFSET :offset ';
$command = $connection->createCommand($sql);
$command->bindParam(":type",$this->type,PDO::PARAM_INT);
$command->bindParam(":code",$this->code,PDO::PARAM_INT);
$command->bindParam(":limit",$limit,PDO::PARAM_INT);
$command->bindParam(":offset",$offset,PDO::PARAM_INT);
$rowArray = $command->queryAll();
return $rowArray;
}
public function getHelpCount(){
$sqlCount='SELECT COUNT(1) from tbl_help';
$count=Yii::app()->db->createCommand($sqlCount)->queryScalar();
return $count;
}
VIEW
<?php $this->widget('ext.yiinfinite-scroll.YiinfiniteScroller', array(
'contentSelector' => '#helps',
'itemSelector' => 'div.help',
'loadingText' => 'Loading...',
'donetext' => '',
'pages' => $pages,
));
?>
<div id="helps">
<?php foreach($helps as $help): ?>
<div class="help">
<p> <?php echo $help['subject']; ?></p>
</div>
<?php endforeach; ?>
</div>
Issues Noticed
- If the page size is more than total records size , the records are displaying again and again … I mean if the page size is 25 and total records are 10 … then page displays 25 records that includes all the 10 records two times and then the first 5 records again . To avoid this I used below code
if($totalCount < 25)
$pageSize=$totalCount+0;
else
$pageSize=25;
-
In the above code I have to say $totalCount+0; some how the $totalCount coming as string from getHelpCount() method
-
Even after displaying all the 10 records if I use the above condition to setup pagesize still I am seeing "Next" link to take me to the next page …where in fact no records exists …
Could some one let me know am I taking the right approach or am I missing some thing ?
Thanks for your help
Regards
Yii Fan