Ok, I found the problem everyone.

For anyone also having this problem, it is the default pagination.

var $paginate = array('limit' => 100, 'page' => 1, 'sort' => 'name',
'direction' => 'asc');

If you set a default sort and direction in your controller, all of
your sorting will only work in one direction.

In the case above, the only link it would create in for the field
'name' was a 'desc' one. Conversely, for all other fields it would
only create an 'asc' one.

One I took them out:

var $paginate = array('limit' => 100, 'page' => 1);

All of the sorting links worked fine, in both directions. My
suggestion is if you want to have a default sort/direction, just pass
them as arguments from the referring page:

/controller/index/sort:name/direction:asc/

Will

On Oct 21, 1:26 am, Will Poillion <[email protected]> wrote:
> I've been pulling my hair out on this for a while now, and it just
> seems like the pagination sorting isn't working correctly.
>
> Using the defaults views/controllers created by cakebake, I get these
> headers in my view and this index function in my controller.
>
> <th><?php echo $paginator->sort('name');?></th>
> <th><?php echo $paginator->sort('cas_num');?></th>
>
>         function index() {
>                 $this->Ingredient->recursive = 2;
>                 $this->set('ingredients', $this->paginate());
>         }
>
> But it only sorts the fields ascending. Once you click to sort by that
> field, it does not automatically change the link to sort the same
> field descending. So, if you click Name, you get Name ascending, no
> matter how many times you press it.
>
> I've even tried to force it to create the link differently by passing
> the arguments sent to my controller:
> $this-params['named']['sort'] and
> $this-params['named']['direction']
>
> BACK to my view, and then doing if statements:
>
> <th><?php
>         if ($sortField == 'cas_num' && $sortOrder == 'asc'){
>                echo $paginator->link('Cas Num', array('sort' =>
> 'cas_num', 'direction' => 'desc'));
>         } else {
>                 echo $paginator->link('Cas Num', array('sort' => 'cas_num',
> 'direction' =>'asc'));
>
>         ?>
> </th>
>
> And the $sortField and $sortOrder variables are being set fine. I've
> been checking them with outputs. And it is calling this function
> correctly:
>
>                echo $paginator->link('Cas Num', array('sort' =>
> 'cas_num', 'direction' => 'desc'));
>
> But it is NOT creating a link that sets the direction to desc. The
> link it creates is STILL an ASC link.
>
> I don't know what I'm doing wrong. I would be so very appreciative of
> anyone that can shed some light on this for me!!
>
> Thank you!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to