如何自定义CakePHP分页URL?

41ik7eoe  于 2023-11-19  发布在  PHP
关注(0)|答案(3)|浏览(203)

目前我正在使用cakephp版本2.5.3
我想改变我的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'));
?>

字符串
上面的页码显示-
x1c 0d1x的数据
当我点击2然后链接将http://www.example.com/newsFeeds/ajax_news_feed/my_post/page:2,但我需要http://www.example.com/newsFeeds/index/my_post/page:2
请告诉我如何在分页中更改控制器和操作?

swvgeqrz

swvgeqrz1#

User $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'));
?>

字符串

mrzz3bfm

mrzz3bfm2#

对于cakephp 3,它有点不同:

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

字符串

rqqzpn5f

rqqzpn5f3#

首先我使用了这个$this->Paginator->options(array($this->passedArgs));。但是为了改变控制器和操作,我使用了下面的代码。

<?php $url = array('controller' => 'customer_deposits', 'action' => 'accounting_bucket'); 
$this->passedArgs = array_merge($url, $this->passedArgs); 
$this->Paginator->options['url'] = $this->passedArgs;

字符串
通过这种方式,您可以更改URL并使用更改后的URL的传入参数。

相关问题