passing parameters to zend paginationControl partial

余生颓废 提交于 2019-12-10 03:14:29

问题


I have a page that displays a lot of data, including Zend_Paginator. The page action is /po/fetch?id=someID.

what i want to do is to pass the "id" parameter to zend paginationControl so the pagination links will be something like /po/fetch?id=someID&page=somePage. unfortunally i can't find anywhere explanation on how i can pass that parameter to the paginationControl.

my call to paginationControl:

echo $view->paginationControl($paginator, 'Sliding',$control, $params);

where $params = array('id' => someID

and my pagination partial is:

<a href=<?= $url.'&page='.$this->first; ?> id="first"> First </a>

<a href=<?= $url.'&page='.$this->previous; ?> id="previous">&lt; Previous</a>

<?php 
foreach($this->pagesInRange as $page) {
?>
        <a href="<?= $url.'&page='.$page; ?>">.$page.</a>  | ;
<?php 
}
?>

<a href=<?= $url.'&page='.$this->next;?> id="next"> Next &gt;</a>

<a href=<?= $url.'&page='.$this->last; ?> id="last"> Last </a>

and I want $url to be of the specified form.


回答1:


$this->id 



回答2:


Hey Try this, It will surely work.....

<a href="<?php echo $this->url(array('page' => $page,'id'=>'1')); ?>">
    <?php echo $page; ?>
</a>

Here 1 is given as the id you have to pass the id you want....... Like

<a href="<?php echo $this->url(array('page' => $page,'id'=>$param['id'])); ?>">
        <?php echo $page; ?>
    </a>



回答3:


Your example code doesn't show how $url is populated, but you really should be using the URL ViewHelper.

So, for example - your previous link would become:

<a href=<?php echo $this->url(array('page' => $this->previous)); ?> id="previous">&lt; Previous</a>

This will return a proper URL to the current page with the page parameter set to $this->previous. So if the current url is /users/view?foo=bar&page=5, the above code would output /users/view?foo=bar&page=4 for the previous link. Notice how any query parameters that are already present are preserved.

So, if the id parameter is already present on the URL showing your paginator, the above code will "just work". However, if you still need to add the id parameter, you can do so like this:

<a href=<?php echo $this->url(array('page' => $this->previous, 'id' => $this->id)); ?> id="previous">&lt; Previous</a>

To continue from our previous example, this code would output the following url: /users/view?foo=bar&page=4&id={someId}

Here is the reference documentation for the URL ViewHelper:

url($urlOptions, $name, $reset): Creates a URL string based on a named route. $urlOptions should be an associative array of key/value pairs used by the particular route.

One last note - the $reset (third) parameter of the URL ViewHelper will come in very handy. The default behavior is to preserve any query parameters of the current request but calling $this->url(array(), 'default', true) with true for the $reset parameter will basically remove all parameters except for the ones you specify in $urlOptions.




回答4:


I have gone through the same issue so I have used code given below in partial paginator.

I have created a function in paginator partial view file(control.phtml) or may be different.

function queryStr($p){
    $params = $array = Zend_Controller_Front::getInstance()->getRequest()->getQuery();
    $params['page']=$p;
    $str='?';
    foreach($params as $k=>$v){
        if($v)
           $str .= $k.'='.$v.'&';
    }
    return $str;
}

Now for links I am using code given below.

<a href="<?php echo queryStr($page); ?>">

Instead of

<a href="<?php echo $this->url(array('page' => $page)); ?>">

I am sure it will be helpful to others as well.



来源:https://stackoverflow.com/questions/5747673/passing-parameters-to-zend-paginationcontrol-partial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!