我正在尝试进行 yii 分页并遵循此示例。它似乎对我不起作用。我想对一个字符串值数组进行分页。以下是我所拥有的:
控制器
$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); // the trick is here!
$this->render('index',array(
"location"=>$location,
"files"=>$files,
'item_count'=>$item_count,
'page_size'=>Yii::app()->params['listPerPage'],
'pages'=>$pages
));
看法
<div id="main">
<table>
<?php foreach($files as $q): ?>
<form>
<tr>
<td rowspan=2>
<div>
<object data="<?php echo '/data/scan/invoice/'.$q; ?>" type="application/pdf">
<p>
It appears you don't have a PDF plugin for this browser. No
biggie... you can <a href="#">click
here to download the 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'),
));
字符串值数组是文件路径,将用于在对象查看器中显示 pdf 文件。