passing parameters to zend paginationControl partial

不问归期 提交于 2019-12-05 02:27:04
$this->id 

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>

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.

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.

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