posting the result here for future searches on the subject.
Apparently this inheritance is the intended behavior of the Paginator
helper. Personally this makes no sense to me, but I guess there must
be good reason for it.
If you need a link that doesn't adapt to the current parameters (e.g.
having a permanent direction:desc) then it's recommended to use
HtmlHelper::link. The links generated with this do not change, thus
giving the desired results.
For example, in my index.ctp view I changed;
echo $paginator->link('Recent', array('sort'=>'released',>
'direction'=>'desc');
to
echo $html->link('Recent', array('sort' => 'released', 'direction' =>
'desc'));
-- Mike
On Feb 15, 11:49 am, Mike Cook <m...@epubbooks.com> wrote:
> 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:deschttp://localhost/books/index/page:1/sort:released/direction:deschttp://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+unsubscribe@googlegroups.com
For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---
No comments:
Post a Comment