1)我如何访问分页器部分内的搜索
$keyword
以创建友好的搜索网址?显然,将关键字作为 $this->view->paginator->keyword 传递是行不通的。2) 目前,搜索按钮的名称也作为 param 发送。例如,当搜索“a”时,网址将变为
http://localhost/search/index/search/a/submit//page/2
。有什么办法可以阻止这个吗? 搜索表格:
<form id="search" method="get" action="/search">
<input id="searchfield" onClick="this.value=''" type="text" name="search" value="Search wallpapers"/>
<input id="searchbutton" type="submit" value="" name="submit"/>
</form>
searchController 内的操作:
public function indexAction()
{
$keyword=$this->_request->getParam('search');
$alnumFilter=new Zend_Filter_Alnum();
$dataModel=new Model_data();
$adapter=$dataModel->fetchPaginatorAdapter("title LIKE '%".$keyword."%'", '');
$paginator=new Zend_Paginator($adapter);
$paginator->setItemCountPerPage(18);
$page=$this->_request->getParam('page', 1);
$paginator->setCurrentPageNumber($page);
$this->view->paginator=$paginator;
$this->view->keyword=$keyword;
}
index.phtml(视图)文件:
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml');?>
</div>
search-paginator-control.phtml 文件:
if ($this->pageCount){
$params=Zend_Controller_Front::getInstance()->getRequest()->getParams();
if(isset($this->previous)){
?>
<a href="<?php echo $this->url(array_merge($params,array('page'=>$this->previous)));?>">Previous</a>
<?php
}
else{
?> Previous <?php
}
foreach($this->pagesInRange as $page){
if($page !=$this->current){
?>
<a href="<?echo $this->url(array_merge($params,array('page'=>$page)));?>"><?=$page;?></a>
<?
}
else{
echo $page;
}
}
if(isset($this->next)){
?>
<a href="<?php echo $this->url(array_merge($params,array('page'=>$this->next)));?>">Next</a>
<?php
}
else{
?> Next <?php
}
}
paginationControl 视图助手接受第四个参数,即参数数组,因此在您的情况下,您可以执行以下操作:
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml', array('keyword' => $this->keyword));?>
</div>
然后您可以使用 $this->keyword 在分页中访问它。