I had posted about this previously but I guess the title and
explanation I used were not very good. Hopefully this will be better.

Here is my code;

// Controller
  function index() {
    $this->paginate['Book'] = array(
      'contain' => array('Author', 'Language', 'Genre'),
      'order'   => 'title asc'
    );
    $this->set('books', $this->paginate());
  }

// index.ctp view
<ul>
  <li><?php echo $paginator->sort('Title', 'title'); ?></li>
  <li><?php echo $paginator->link('Recent', array('sort'=>'released',
'direction'=>'desc'); ?></li>
  <li><?php echo $paginator->sort('Language', 'Language.code'); ?></
li>
</ul>

When the view loads the links are;

http://localhost/books/index/page:1/sort:title/direction:desc
http://localhost/books/index/page:1/sort:released/direction:desc
http://localhost/books/index/page:1/sort:Language.code/direction:asc

(I am trying to force the 'Recent' sort order to always default to
'desc')

These all work as expected when the link is clicked for the first time
on the initial page load. The problem I am having is with the
$paginator->link(‘Recent’, ...) sort, which is inheriting the model
from the previous sort that was made.

So, if I click ‘Title’ followed by the ‘Recent’ link, I get this URL;

http://localhost/books/index/page:1/sort:Book.released/direction:desc

As you can see, the link has inherited ‘Book.released’. If I click
‘Language’ then the released link becomes ‘Language.released’. The
direction is also being inherited depending on the previous sort
order.

Even if I set the link in the view to use ‘Book.released’;

$paginator->link('Recent', array('sort'=>'Book.released',
'direction'=>'desc');

It still inherits the model, ‘Language.released’. The $paginator->sort
always plays nice as the 'Title' link remains as 'sort:title'.

So, is this a bug with $paginator->link, and if not can anyone advise
me on how to get it working properly?

Thanks,
Mike
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to