开发者

accessing request parameters inside paginator partial

  • 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($pa开发者_JS百科ge !=$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
    }
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜