cakephp 1.3, how to use Paginator->sort() for two

2019-08-05 10:08发布

问题:

i have a simple application where i view some posts from a database and i use Paginator->sort to sort.

What i did is i duplicate everything so that i show the posts twice as well as the sorting. something like this:

link_sort
post1
post2
post3
link_sort
post1
post2
post3

But when i click link_sort both post display get sorted, and i could see that because they are the same. But how can i make it unique so that one link sorts one post display and another one the other one :).

here is some code:

<div class="sort"><?php echo $this->Paginator->sort('title');?></div>
<div class="sort"><?php echo $this->Paginator->sort('body');?></div>
<div class="content_title"><?php echo $post['Post']['title']; ?></div>
<div class="content_body"><?php echo $post['Post']['body']; ?></div>

<div class="sort"><?php echo $this->Paginator->sort('title');?></div>
<div class="sort"><?php echo $this->Paginator->sort('body');?></div>
<div class="content_title"><?php echo $post['Post']['title']; ?></div>
<div class="content_body"><?php echo $post['Post']['body']; ?></div>

any ideas? thanks

回答1:

I think this will work - create two different variables in the controller:

$paginate1 = $this->paginate('conditions...') $paginate2 = $this->paginate('conditions...')

if am not mistaken I had a similar problem once and this is how I solved it.