2014-09-29 145 views
1

目前我使用的是cakephp版本2.5.3如何自定義CakePHP分頁url?

我想改變我的cakephp分頁url。

我現在的網址是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

請告訴我如何更改分頁控制器和操作?

+0

你嘗試做出努力routes.php文件 – Abhishek 2014-09-29 11:02:18

回答

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')); 
?> 
+0

是一個URL路徑很好謝謝... :) – Developer 2014-09-29 11:37:08

1

對於CakePHP的3它的一點點不同:

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

謝謝親愛的回答... :) – Developer 2017-03-31 12:14:56