gpt4 book ai didi

php - Zend中的分页不起作用

转载 作者:行者123 更新时间:2023-12-04 19:38:48 25 4
gpt4 key购买 nike

我有一系列项目。项目是文件路径。我已经设置了分页,但是当我单击下一步时它不会改变。我想每页显示 1 个 pdf。下面是我的代码

class IndexController extends Zend_Controller_Action
{

public function init(){}

public function indexAction()
{
if($_SERVER['SERVER_NAME']=="portal-dev"){
$location = "/data/scan/invoice";
$listOfFiles = $this->readFiles($location);
$paginator = Zend_Paginator::factory($listOfFiles);
$paginator->setItemCountPerPage(1);
$this->view->paginator = $paginator;
}
}


public function readFiles($location){
$pattern="(\.pdf$)"; //valid image extensions
$thelist = array();
if ($handle = opendir($location)) {
while (false !== ($file = readdir($handle)))
{
if (eregi($pattern, $file)) //if this file is a valid image
{
$thelist[] = $file; //insert files into array
$max = count($thelist) - 1;
$max1 = count($thelist);
}
}
closedir($handle);
}
return $thelist;
}
}

索引.phtml
<div id="main">
<?php if(!$this->paginator){
echo "No Files to process";
}else{
?>
<table>
<tr>
<td rowspan=2></td>
<td></td>
</tr>
<tr>
<td></td>
</tr>

</table>
<?php if (count($this->paginator)): ?>
<ul>
<?php foreach ($this->paginator as $item): ?>
<li><?php echo $item; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>

<?php echo $this->paginationControl($this->paginator,'Sliding','partial/my_pagination_control.phtml'); ?>
<?php }?>
</div>

分页在目录部分中找到
<?php if ($this->pageCount): ?>
<div
class="paginationControl">
<!-- Previous page link -->
<?php if (isset($this->previous)): ?>
<a href="<?php echo $this->url(array('page' => $this->previous)); ?>">
Previous </a> <span class="bar"> | </span>
<?php else: ?>
<span class="disabled"> Previous</span> <span class="bar"> | </span>
<?php endif; ?>

<!-- Numbered page links -->
<?php foreach ($this->pagesInRange as $page): ?>
<?php if ($page != $this->current): ?>
<a href="<?php echo $this->url(array('page' => $page)); ?>"> <?php echo $page; ?>
</a> <span class="bar"> | </span>
<?php else: ?>
<?php echo $page; ?>
<span class="bar"> | </span>
<?php endif; ?>
<?php endforeach; ?>

<!-- Next page link -->
<?php if (isset($this->next)): ?>
<a href="<?php echo $this->url(array('page' => $this->next)); ?>"> Next
</a>
<?php else: ?>
<span class="disabled">Next </span>
<?php endif; ?>
</div>
<?php endif; ?>

最佳答案

在 indexAction 中设置当前页码后尝试

$paginator->setCurrentPageNumber($this->_getParam('page'));

像这样
$paginator = Zend_Paginator::factory($listOfFiles);
$paginator->setItemCountPerPage(1);
$paginator->setCurrentPageNumber($this->_getParam('page'));
$this->view->paginator = $paginator;

关于php - Zend中的分页不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15130536/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com