1
votes

I am trying to implement pagination with custom url, when i try to paginate to the next page i am getting the following error.

The requested address '/adminuser/userlist/page:2' was not found on this server.

Here adminuser is the name of the admin user and userlist is the method to get all the users under this adminuser.

The url will look like this http://domain.com/adminuser/userlist

Here is my code

In view:

<?php $this->paginator->options(array('url' => 
array('path'=>$this->params['path']))); ?>
<div class="pagination">
    <ul>
        <li class="prevnext disablelink">
       <?php echo str_replace('/users/','',$this->paginator->prev('« Prev'));?>
        <li>
        <?php  echo str_replace('/users/','',$this->paginator->numbers());?>
        </li>
        <li class="prevnext">
        <?php  echo str_replace('/users/','',$this->paginator->next('Next »'));?>

    </ul>
</div>

routes.php

Router::connect('/:sluguser/:action', array('controller' => 'users', 'action' => 'userlist'),array('pass' => array('sluguser')));
1

1 Answers

0
votes

For pagination, using the default 'paramType' => 'named' you will need to extend your route to accept also the page parameter (as well as sort and direction). In your routes.php, you can add following:

// Parse only default parameters used for CakePHP's pagination:
Router::connectNamed(false, array('default' => true));
// the route to your controller action and wildcard (*) for the possible named parameter
Router::connect('/:sluguser/:action/*', array('controller' => 'users', 'action' => 'userlist'),array('pass' => array('sluguser')));

Btw. As I have found out recently named parameters are deprecated and totally removed in CakePHP 3.x, so consider using $this->paginate['paramType'] = 'querystring'; instead. Then it will work without those additional routes above.