Following Marc Christenfeldt's advice in comment #7 to this Bakery
article: http://bakery.cakephp.org/articles/view/advanced-pagination-1-2
I copied paginator.php to my app/views/helpers directory and changed
the line

    return preg_replace('/.*\./', '', key($options['order']));

in the function sortKey to

    return preg_replace( sprintf( '/%s\./', $this->defaultModel()),
'', key($options['order']));

Now I can use $paginator->sort('Sender', 'Sender.username'); and
clicking on the TH link now results in Paginator acknowledging the
correct sorting direction and rendering the link with the opposite
direction.

To be honest I really doubt it this hasn't been fixed already
(afterall that comment is from the middle of last November), but since
noone ever responded here with an alternative (and hopefully correct)
solution , or as a comment to the above mentioned Bakery article, I
just had to use it, as I didn't have any other way of achieving my
goal.

This of course only solves my first problem and I still needed a way
to tell which of Sender.username and Recipient.username was the
correct sortKey, because $paginator->sortKey() returns just 'username'
inspite of the fact that the named arg is Sender.username. So I
tackled this by testing against the named param directly:

$sortDir = $paginator->sortDir();
$sortKey = $paginator->sortKey();
if('username' == $sortKey) {
    if(!empty($this->params['named']['sort'])) {
        switch($this->params['named']['sort']) {
            case 'Sender.username':
                $sender_options['class'] = $sortDir;
                break;
            case 'Recipient.username':
                $recipient_options['class'] = $sortDir;
                break;
        }
    }
}

On Feb 29, 11:31 am, Nasko <[EMAIL PROTECTED]> wrote:
> Anyone?
>
> I guess sorting by a foreign model should be a trivial matter and I'm
> probably just missing some major  clue in the API or the manual, but
> I'm surprised there's noone that knows where I should be looking for
> it :-)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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