Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing parameters to zend paginationControl partial

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.

like image 229
Boris C Avatar asked Apr 21 '11 17:04

Boris C


3 Answers

$this->id 
like image 162
Dmitry Z. Avatar answered Sep 25 '22 17:09

Dmitry Z.


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>
like image 25
Pushpendra Avatar answered Sep 23 '22 17:09

Pushpendra


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.

like image 22
leek Avatar answered Sep 23 '22 17:09

leek