diff --git a/lib/Cake/Controller/Component/PaginatorComponent.php b/lib/Cake/Controller/Component/PaginatorComponent.php index 6e34fa6d7..85f8ab6b0 100644 --- a/lib/Cake/Controller/Component/PaginatorComponent.php +++ b/lib/Cake/Controller/Component/PaginatorComponent.php @@ -382,13 +382,13 @@ class PaginatorComponent extends Component { } return $options; } - if (!empty($options['order']) && is_array($options['order'])) { $order = array(); foreach ($options['order'] as $key => $value) { if (is_int($key)) { - $key = $value; - $value = 'asc'; + $field = explode(' ', $value); + $key = $field[0]; + $value = count($field) === 2 ? trim($field[1]) : 'asc'; } $field = $key; $alias = $object->alias; diff --git a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php index 087b92029..9da2a1fe4 100644 --- a/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php +++ b/lib/Cake/Test/Case/Controller/Component/PaginatorComponentTest.php @@ -326,6 +326,12 @@ class PaginatorComponentTest extends CakeTestCase { $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id'); $this->assertEquals(array(1, 2, 3, 4, 5, 6), $results); + $Controller->Paginator->settings = array( + 'order' => array('PaginatorControllerComment.id DESC') + ); + $results = Hash::extract($Controller->Paginator->paginate('PaginatorControllerComment'), '{n}.PaginatorControllerComment.id'); + $this->assertEquals(array(6, 5, 4, 3, 2, 1), $results); + $Controller->Paginator->settings = array( 'order' => array('PaginatorControllerPost.id' => 'ASC') ); @@ -629,6 +635,17 @@ class PaginatorComponentTest extends CakeTestCase { 'PaginatorControllerPost.created' => 'asc' ); $this->assertEquals($expected, $result['order']); + + $Controller->PaginatorControllerPost->order = array( + 'PaginatorControllerPost.id ASC', + 'PaginatorControllerPost.created DESC' + ); + $result = $Controller->Paginator->validateSort($Controller->PaginatorControllerPost, array()); + $expected = array( + 'PaginatorControllerPost.id' => 'ASC', + 'PaginatorControllerPost.created' => 'DESC' + ); + $this->assertEquals($expected, $result['order']); } /**