为什么CakePHP 3.2 Paginator不会对我的查询结果进行排序?

时间:2016-06-10 13:32:38

标签: sorting cakephp cakephp-3.x

来自控制器的CakePHP查询等:

Apples.update_all("revokable=true", ["fruit_id=? and id not in ?"], 2, 41)

以下是$ratings = $this->Ratings->find('all')->group('manufacturer'); $ratings->select(['manufacturer', 'count' => $ratings->func()->count('*'), 'max' => $ratings->func()->max('psi_score'), 'min' => $ratings->func()->min('psi_score')]); $ratings = $this->paginate($ratings); $this->set(compact('ratings')); $this->set('_serialize', ['ratings']); 产生的内容:

debug($ratings)

在视图中,'items' => [ (int) 0 => object(Cake\ORM\Entity) { 'manufacturer' => 'A10Green Technology', 'count' => (int) 8, 'max' => '7.41', 'min' => '6.57', '[new]' => false, '[accessible]' => [ '*' => true ], '[dirty]' => [], '[original]' => [], '[virtual]' => [], '[errors]' => [], '[invalid]' => [], '[repository]' => 'Ratings' }, 上的排序工作正常。这是一个原始的db字段。 manufacturercountmax值未进行排序。

以下是视图的min次调用:

sort

1 个答案:

答案 0 :(得分:1)

您需要将要允许排序的字段列入白名单,如:Pagination

public $paginate = [
    'sortWhitelist' => [
        'id', 'title', 'Users.username', 'created'
    ]
];

否则默认情况下,蛋糕3阻止它