-1

I can't display Agreements with agreement_number less than 7 and order it by agreement_number DESC.

I have read Pagination CakePHP Cook Book and can't find where my code is wrong. It display only less than 7, but always ASC. I have found similar question here, [that works],(CakePHP paginate and order by) and do not know why. Agreement.agreement_number is int(4).

        $this->Agreement->recursive = 0;
        $agreements = $this->Paginator->paginate('Agreement', array(
            'Agreement.agreement_number <' => '7'
                ), array(
                'Agreement.agreement_number' => 'desc'
            )
        );
        $this->set('agreements', $agreements);
    }

Exact cake version is 2.5.2.

Community
  • 1
  • 1
tomas3man
  • 29
  • 7

1 Answers1

0

... Where did you read that that was the correct syntax?

The paginate function's third parameter is for sorting (and I mean, within the table... with those down and up arrows).

List of allowed fields for ordering. This allows you to prevent ordering on non-indexed, or undesirable columns.

You have the exact link used for documentation of the API, but you don't seem to be following it (like, from here and here)

$this->Paginator->settings = array(
    'Agreement' => array(
        'order' => array('Agreement.agreement_number' => 'desc')
    )
);

$agreements = $this->Paginator->paginate('Agreement', array(
        'Agreement.agreement_number <' => '7'));
Nunser
  • 4,512
  • 8
  • 25
  • 37