php - yii pagination with array -
i trying yii pagination , followed example. how ever not seem work me. want paginate array of string values. following have:
controller
$location = $this->location($_server['server_name']); $files = $this->getfiles("/data/scan/invoice"); $page = (isset($_get['page']) ? $_get['page'] : 1); $item_count = count($files); $pages = new cpagination($item_count); $pages->setpagesize(yii::app()->params['listperpage']); $criteria = new cdbcriteria(); $pages->applylimit($criteria); // trick here! $this->render('index',array( "location"=>$location, "files"=>$files, 'item_count'=>$item_count, 'page_size'=>yii::app()->params['listperpage'], 'pages'=>$pages ));
view
<div id="main"> <table> <?php foreach($files $q): ?> <form> <tr> <td rowspan=2> <div> <object data="<?php echo '/data/scan/invoice/'.$q; ?>" type="application/pdf"> <p> appears don't have pdf plugin browser. no biggie... can <a href="#">click here download pdf file.</a> </p> </object> </div> </td> <td><input id="lognumber" type="text" /> <input type="button" value="search" onclick="search()"/> <div style="height:40px;width:100%;"> </div> <br> <input type="button" value="save" /> <br> <input type="button"value="delete" /> <br> <div id="lookup"></div> </td> </tr> <tr> <td height="300px"><?php //echo $this->paginationcontrol($this->paginator,'jumping','partial/my_pagination_control.phtml'); ?> </td> </tr> </form> <?php endforeach; ?> </table> </div> <? $this->widget('clinkpager', array( 'currentpage'=>$pages->getcurrentpage(), 'itemcount'=>$item_count, 'pagesize'=>$page_size, 'maxbuttoncount'=>5, //'nextpagelabel'=>'my text >', 'header'=>'', 'htmloptions'=>array('class'=>'pages'), ));
the array of string values filepaths used display pdf files in object viewer.
the problem apply limit on empty cdbcriteria:
$criteria = new cdbcriteria(); $pages->applylimit($criteria); // trick here!
and never use $criteria
. in example apply limit on $criteria
, use fetch data when yii fetching data knows it'll paginated:
$this->render('index',array( 'model'=> modelnamex::model()->findall($criteria), ));
to want you'll need use carraydataprovider
data need paginated.
$dataprovider=new carraydataprovider($files); $dataprovider->setpagination($pages);
and in view you'll need call
$dataprovider->getdata() //will return list of arrays.
Comments
Post a Comment