#6132: paginate->link() - sort inheriting model and direction not being used
--------------------------------+-------------------------------------------
Reporter: epub | Type: Bug
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Helpers
Version: 1.2 Final | Severity: Normal
Keywords: paginator, link | Php_version: PHP 5
Cake_version: 8004 |
--------------------------------+-------------------------------------------
= What I Did: =
In my index.ctp I have these three paginator links (HTML tags removed);
{{{
echo $paginator->sort('Title', 'title');
echo $paginator->link('Recent', array('sort'=>'released',
'direction'=>'desc');
echo $paginato->sort('Language', 'Language.code');
}}}
The Model.fields are;
* Book.title
* Book.released
* Language.code
= What I Expected to Happen: =
Both 'Title' and 'Language' work as expected; ordering by the correct
field and direction, switching between ASC and DESC as needed.
I want 'Recent' to always be forced to a DESC direction, no matter which
sort was previously done with the other links. This is what I expect to
happen by using $paginator->link() and stating these parameters.
= What Actually Happens: =
[[BR]]
'''SORT'''
[[BR]][[BR]]
'''sort:field''' becomes '''sort:Model.field'''
[[BR]][[BR]]
The $paginator->link('Recent', ...) sort is inheriting the model from the
previous sort that was made, so when I click 'Title' and then the 'Recent'
link, I get this URL;
{{{
http://localhost/books/index/page:1/sort:Book.released/direction:desc
}}}
As title and recent are both in the same model this is okay, but when I
sort with the Language model, '''sort:released''' becomes
'''sort:Language.released''', which of course gives an error.
[[BR]]
'''DIRECTION'''
[[BR]][[BR]]
The direction is also ignoring the DESC that I set in the
$paginator->link.
= How I Fixed This: =
I made the following changes to the paginator.php file in '''function
url()''' - line 273.
[[BR]]
'''SORT'''
[[BR]][[BR]]
To stop the inheritance of the model I '''REMOVED lines 283-286'''
{{{
if (strpos($key[0], '.') !== false) {
list($model) = explode('.', $key[0]);
$sort = $model . '.' . $sort;
}
}}}
[[BR]]
'''DIRECTION'''
[[BR]][[BR]]
To fix the direction problem I '''changed line 280''' to;
{{{
if (isset($url['direction'])) {
list($sort, $direction) = array($this->sortKey($model, $url),
$url['direction']);
} else {
list($sort, $direction) = array($this->sortKey($model, $url),
current($url['order']));
}
}}}
= Please Note: =
This is my first Cake project and I am not such a strong programmer.
I don't know if these changes will have ramifications on other parts of
paginator, but so far they are working for me.
--
Ticket URL: <https://trac.cakephp.org/ticket/6132>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets 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/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---