Reputation: 2706
currently i am using cakephp version 2.5.3
I want to change my cakephp pagination url.
My current URL is http://www.example.com/newsFeeds/ajax_news_feed/page:2
I need http://www.example.com/newsFeeds/index/page:2
My Code:
<?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'));
?>
Above pagination is showing-
When i am clicking 2
then the link is going to http://www.example.com/newsFeeds/ajax_news_feed/my_post/page:2
but i need http://www.example.com/newsFeeds/index/my_post/page:2
Please tell me how to change controller and action in pagination?
Upvotes: 1
Views: 6112
Reputation: 47
First I used this one $this->Paginator->options(array($this->passedArgs));
. But to change the controller and the action I used the below code.
<?php $url = array('controller' => 'customer_deposits', 'action' => 'accounting_bucket');
$this->passedArgs = array_merge($url, $this->passedArgs);
$this->Paginator->options['url'] = $this->passedArgs;
By using this way, you can change the url and use the passed arguments with the changed url.
Upvotes: 0
Reputation: 2252
For cakephp 3 its a little bit different:
$this->Paginator->options([
'url' => [
'controller' => 'newsFeeds',
'action' => 'index',
'my_post']
]);
Upvotes: 2
Reputation: 3414
User $this->Paginator->options
-
Code:
<?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'));
?>
Upvotes: 4