Zend framework 2, pagination routing issue

4.1k views Asked by At

I have issue on zend pagination and routing in zf2 . I would like to display details of feedback item , and list of its sub items ( actions ) on the same page . My route code is given below

$routes['dashboard_inbox_actions'] =  array(
    'type'      => 'segment',
    'options'   => array(
        'route' => '/dashboard/inbox/detail[/:feedback[/actions/page/:page]]',
        'constraints' => array(  
            'feedback'     => '[0-9]+',
            'page'         => '[0-9]+',
        ),
        'defaults' => array(      
             '__NAMESPACE__' => 'Dashboard\Controller',
            'controller'    => 'inbox' ,
            'action'        => 'detail',                
            'feedback'      => 0 ,
            'page'          => 1
        ),
    ),
);

I pass url like

/dashboard/inbox/detail/4

in listing page , for rendering the provided pages of subitems .

<?php echo $this->paginationControl($this->paginator, 'Sliding' ); ?>

which creates paging urls , with feedback id as 0 ( it my issue )

/dashboard/inbox/detail/0/actions/page/2
/dashboard/inbox/detail/0/actions/page/3

I manually paste url

 /dashboard/inbox/detail/4/actions/page/2

Its shows page 2 as active item . My controller code works fine and gives me result , but still paginationControl creates url with feedback id 0.

1

There are 1 answers

0
Andrew On BEST ANSWER

You need to use the fourth parameter of the paginationControl view helper:

<?php 
    echo $this->paginationControl($this->paginator, 'Sliding',
          'my_pagination_control', array('route' => 'paginator_route')); 
?>

You can pass through parameters to the view partial, for example pass through your route name so you can generate yoru links using the correct route.

then inside your view partial you can use this in the url helper:

<?php echo $this->url($this->route, array('page' => $this->first), FALSE, TRUE) ?>

see: http://framework.zend.com/manual/2.0/en/modules/zend.view.helpers.html#url-helper where you can see the url helper can use currently matches params:

url($name, $urlParams, $routeOptions, $reuseMatchedParams)

Setting $reuseMatchedParams to true will allow the use of the current matched params as default values.