在同一控制器中的两个不同动作的分页
I have an action called index
and another one called manage
, both in PostsController
. I want to implement pagination for both, and I've set up this class attribute:
public $paginate = array(
'limit' => 10,
'order' => array(
'Post.created' => 'desc'
)
);
then I'm using the pagination in my index
action like so: $this->set('posts', $this->paginate('Post'));
This results in a URL like so: http://dev/posts/page:2
which is fine.
However, when I try to use pagination in my manage
action just like I did with index
($this->set('posts', $this->paginate('Post'));
), the pagination links on my view redirect to the URL above, rather than the manage action.
Basically, Cake is getting confused because I'm using pagination twice in the same controller and it's redirecting both to the same URL. How can I make sure that the pagination for the manage
action works properly?
我有一个名为 然后我正在使用 我的 这会生成如下所示的URL: 但是 ,当我尝试在 基本上,Cake正在变得混乱 因为我在同一个控制器中使用了两次分页,并且它将两个重定向到同一个URL。 如何确保 index code>的动作,另一个名为
manage code >,都在
PostsController code>中。 我想为两者实现分页,并且我已经设置了这个类属性: p>
public $ paginate = array(
'lim''> 10,
'order'=>数组(
'Post.created'=>'desc'
)
);
code> pre>
index code>操作中的分页如下:
$ this-> set('posts',$ this-> paginate('Post')); code> p >
http:// dev / posts / page:2 code>,这很好。 p>
manage code>操作中使用分页时,就像我使用
index code>(
$ this-> set('posts',$ this-&gt ; paginate('Post')); code>),我视图中的分页链接重定向到上面的URL,而不是管理操作。 p>
manage code>操作的分页正常工作? p>
div>
Do the followings.
<?php
class PostsController extends AppController
{
var $name = 'Posts';
public $paginate = array
(
'limit' => 10,
'order' => array
(
'Post.created' => 'desc'
)
);
function index()
{
$this->Post->recursive = 0;
$this->set('posts', $this->paginate('Post'));
}
function manage()
{
$this->Post->recursive = 0;
$this->set('posts', $this->paginate('Post'));
}
}
make changes in view file as defined below.
index.ctp
$options = array
(
'url'=> array
(
'controller' => 'posts',
'action' => 'index'
)
);
$paginator->options($options);
manage.ctp
$options = array
(
'url'=> array
(
'controller' => 'posts',
'action' => 'manage'
)
);
$paginator->options($options);
And you are done.