访问分页器部分内的请求参数

发布于 2024-11-07 13:44:56 字数 2658 浏览 0 评论 0原文

  • 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

南…巷孤猫 2024-11-14 13:44:57

paginationControl 视图助手接受第四个参数,即参数数组,因此在您的情况下,您可以执行如下操作:

<div id="page-links">

    <?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml', array('keyword' => $this->keyword));?>       

</div>

然后您使用 $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:

<div id="page-links">

    <?= $this->paginationControl($this->paginator,'Sliding','partials/search-pagination-control.phtml', array('keyword' => $this->keyword));?>       

</div>

Then you access it inside your pagination using $this->keyword.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文