开发者

Cakephp, Custom Routes and Pagination - pagination params passed wrong

i do have a problem with custom routes and pagination. i read every thread i could find, but noone seemed to have this very same problem.

what i did is connecting this route:

Router::connect('/a/:username/*', array('controller' => 'users', 'action' => 'view'),array('pass' => array('username'),'username' => '[^-]+'));

this totally works for my users (i changed the users/view action to accept usernames instead of ids).

But our user profiles are kind of blogs in which you can paginate all posts of a user. so ich changed the pagination links to this:

    $paginator->options(array('url'=> array('controller' => 'users',
                                            'action' => 'view',
                                            'username' => strtolower($user['User']['username']) ,
                                        ),
    ));

and

<div class="pagination">
    <?php if($this->Paginator->hasPrev()): ?>
    <?php echo $this->Paginator->prev(__('Previous', true), null, null, array('class' => 'disabled')); ?>
    <?php endif;?>
    <?php echo $this->Paginator->numbers(array('separator' => '')); ?>
    <?php if($this->Paginator->hasNext()): ?>
    <?php echo $this->Paginator->next(__('Next', true), null, null, array('class' => 'disabled')); ?>
    <?php endif; ?>
</div>

This also does work in case of link generation. the paginator does create the wanted links like

domain/username/page:2

My problem is that the username is not passed correctly. when debugging $this->params in users/view the "pagination p开发者_运维百科arameters" are handled like a part of the "user parameter". in this case i get:

[controller] => users
[action] => view
[username] => tim/page:2
[named] => Array
    (
    )

[pass] => Array
    (
        [0] => tim/page:2
    )

where tim is the username and page:2 just the pagination param. but for some reason both parameters are written into one instead of the username into 'username' and the page into the named page parameter. after the users/view action rejecting the call (cos there is no such user) the the app tries to route to the same view with the user-id instead of the name in a loop and stops after too many redirects.

i really have no idea why the pagination parameters are passed in to the username. if anyone had an idea, what i am doing wrong, it would make me very very happy. :-)


the problem is your regex: Router::connect('/a/:username/*', array('controller' => 'users', 'action' => 'view'),array('pass' => array('username'),'username' => '[^\/]+'));

Or may be \w+ (I don't know the criteria for your username.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜