访问分页器部分内的请求参数
1)我如何访问分页器部分内的搜索
$keyword
以创建友好的搜索网址?显然,将关键字作为 $this->view->paginator->keyword 传递是行不通的。2) 目前,搜索按钮的名称也作为 param 发送。例如,当搜索“a”时,URL 变为
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(视图)文件:
partialLoop('wallpaper/table-row.phtml',$this->paginator) ;?>
<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
}
}
1)how do i access the search
$keyword
inside the paginator partial to create search freindly urls ? clearly, passing the keyword as $this->view->paginator->keyword doesnt work.2) currently, the search button's name is also send as param . for eg when searching for 'a' the url becomes
http://localhost/search/index/search/a/submit//page/2
. any way to stop this ?
Search Form:
<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>
Action inside 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 (view) file:
partialLoop('wallpaper/table-row.phtml',$this->paginator) ;?>
<div id="page-links">
<?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml');?>
</div>
search-paginator-control.phtml file:
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
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
paginationControl 视图助手接受第四个参数,即参数数组,因此在您的情况下,您可以执行如下操作:
然后您使用 $this-> 关键字在分页内访问它。
The paginationControl view helper accepts a 4th parameter, that is a array of parameters, so in your case you could do something like this:
Then you access it inside your pagination using $this->keyword.