如何自定义CakePHP分页URL?

时间:2014-09-29 10:52:34

标签: cakephp pagination

目前我正在使用cakephp版本2.5.3

我想改变我的cakephp分页网址。

我当前的网址为http://www.example.com/newsFeeds/ajax_news_feed/page:2我需要http://www.example.com/newsFeeds/index/page:2

我的代码:

<?php
    echo $this->Paginator->prev(' <<' . __('Previous  '), array(), null, array('class' => 'prev disabled'));
    echo $this->Paginator->numbers();
    //echo $this->Paginator->url(array('controller'=>'newsFeeds', 'action'=>'index'));
    //echo $this->Paginator->link('Sort by title on page 5', array('controller'=>'newsFeeds', 'action'=>'index'));
    echo $this->Paginator->next(__('  Next') . '>> ', array(), null, array('class' => 'next disabled'));
?>

以上分页显示 -

tt

当我点击2时,该链接将转到http://www.example.com/newsFeeds/ajax_news_feed/my_post/page:2,但我需要http://www.example.com/newsFeeds/index/my_post/page:2

请告诉我如何在分页中更改控制器和操作?

2 个答案:

答案 0 :(得分:4)

用户$this->Paginator->options -

代码:

<?php
    $this->Paginator->options['url'] = array('controller' => 'newsFeeds', 'action' => 'index/my_post');
    echo $this->Paginator->prev(' <<' . __('Previous  '), array(), null, array('class' => 'prev disabled'));
    echo $this->Paginator->numbers();
    echo $this->Paginator->next(__('  Next') . '>> ', array(), null, array('class' => 'next disabled'));
?>

答案 1 :(得分:2)

对于cakephp 3来说,它有点不同:

$this->Paginator->options([
    'url' => [
        'controller' => 'newsFeeds',
        'action' => 'index',
        'my_post']
    ]);