Hello. Guys tell me how to sort the tasks by 2 fields in pagination? What code is needed? Here's what the view is:

<?php echo $this->Paginator->sort('Created', 'По дате создания'); ?> 

This link is generated for a grade by date, that's what's in the controller

 public function index() { $this->Paginator->settings = [ 'limit' => 5, 'order' => [ 'Task.created' => 'desc' ] ]; $tasks = $this->Paginator->paginate('Task'); $this->set('tasks', $tasks);... 

How to make sorting by 2 fields? More precisely on Task.created and Task.task_type_id Thanks in advance

  • one
    The sort() method accepts only the string name of the field by which sorting is expected. You can sort the data by several fields by adding an element to the settings order => ['created' => 'desc', 'task_type_id' => 'asc'] , but references to sorting with the help of the Paginator->sort() helper are generated only for one field to switch its order ( asc|desc ). - teran
  • If you use sorting order => ['created' => 'desc', 'task_type_id' => 'asc'] then everything is fine, but how then to make a link in the view so that you can change the order (asc | desc) ??? - Ilgam Karimov
  • So about that and speech that the generator of standard links ( sort() method) forms the link for sorting on one field. For the two fields it is not clear how to change the sorting. When one field here is clear - it switches asc-desc, and with two fields, what should it do? You can try to generate the link manually, without using a helper. I am not familiar with cakephp2, as I started working with the 3rd version. not at hand, I can not see. - teran

0