1)如何访问paginator partial中的搜索$keyword
以创建搜索友好网址?显然,将关键字传递为$ this-> view-> paginator->关键字无效。
2)目前,搜索按钮的名称也作为参数发送。例如,当搜索“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
}
}
答案 0 :(得分:9)
paginationControl视图助手接受第4个参数,即参数数组,因此在您的情况下,您可以执行以下操作:
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml', array('keyword' => $this->keyword));?>
</div>
然后使用$ this-&gt;关键字在您的分页内访问它。