Disable the URL query option from Cake PHP 2 paginator generated links

61 Views Asked by At

I'm using the Cake PHP 2 pagination to generate links in my view. The page URL I'm on is:

When I want to navigate forwards though my pages, Cake is adding a url encoded value of my current page route: payday_admin/leads to my URL, along with the limit option. Both of these I don't need, I only need the page number.

How can I disable this?

This is what it looks like:

And here's my markup for the view:

<nav aria-label="Page navigation example">
  <ul class="pagination justify-content-end mb-0">
    <?php
      echo $this->Paginator->prev('Prev', array('tag' => 'li', 'class'=>'page-item', ' class'=>'page-link'), null, array('class' => 'disabled page-item', 'tag' => 'li', 'disabledTag' => 'a', ' class' =>'page-link'));
      echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'tag' => 'li', 'class'=>'page-item', 'currentClass' => 'disabled bg-primary text-white page-link', ' class'=>'page-link','modulus'=>6));
      echo $this->Paginator->next('Next', array('tag' => 'li', 'class'=>'page-item', ' class'=>'page-link'), null, array('class' => 'disabled page-item', 'tag' => 'li', 'disabledTag' => 'a', 'currentClass'=>'page-link', ' class' =>'page-link'));
    ?>
  </ul>
</nav>

And my controller...

// define pagination settings
$this->Paginator->settings = array(
        'Application' => array(
                'paramType' => 'querystring',
                'totalLimit' => 20000,
                'limit' => 20000,
                'maxLimit' => $filters['pagination']['perPage'],
                'fields' => array(
                        'Application.*',
                        'ApplicationPayday.*',
                        'ApplicationApiLink.*',
                        'ApplicationResponse.*',
                        'AffiliateId.*',
                        'Redirect.*'
                ),
                'joins' => array(
                        array(
                                'table' => 'tlp_application_paydays',
                                'alias' => 'ApplicationPayday',
                                'type' => 'LEFT',
                                'conditions' => array(
                                        'ApplicationPayday.application_id = Application.id'
                                )
                        ),
                        array(
                                'table' => 'tlp_application_api_links',
                                'alias' => 'ApplicationApiLink',
                                'type' => 'LEFT',
                                'conditions' => array(
                                        'ApplicationApiLink.application_id = Application.id'
                                )
                        ),
                        array(
                                'table' => 'tlp_application_responses',
                                'alias' => 'ApplicationResponse',
                                'type' => 'LEFT',
                                'conditions' => array(
                                        'ApplicationResponse.application_id = Application.id'
                                )
                        ),
                        array(
                                'table' => 'tlp_affiliate_ids',
                                'alias' => 'AffiliateId',
                                'type' => 'LEFT',
                                'conditions' => array(
                                        'AffiliateId.aff_id = Application.tlp_aff_id'
                                )
                        ),
                        array(
                                'table' => 'tlp_redirects',
                                'alias' => 'Redirect',
                                'type' => 'LEFT',
                                'conditions' => array(
                                        'Redirect.application_id = Application.id'
                                )
                        )
                ),
                'conditions' => array(
                        'Application.modified_timestamp >=' => $initialStartDate,
                        'Application.modified_timestamp <=' => $initialEndDate
                ),
                'group' => array(
                        'Application.id'
                ),
                'order' => array(
                        'Application.id' => 'desc'
                ),
                'recursive' => -1
        )
);

// run query to get applications via paginated settings
$applications = $this->Paginator->paginate('Application');

I just need:

1

There are 1 best solutions below

0
Valeriu Ciuca On

The parameters are added because of 'paramType' => 'querystring' in the Paginator settings. If you remove it and create a route manually, using named parameters like this:

Router::connect(
        '/payday_admin/leads/page::page',
        ['controller' => 'payday_admin', 'action' => 'leads', 'full_path' => '/payday_admin/leads'],
        ['page' => '[0-9]+', 'filter_string' => '[a-z0-9;=\-,\/]+',]
);

Your URLs will be cleaner:

/payday_admin/leads/page:1, /payday_admin/leads/page:2