来自控制器的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字段。 manufacturer
,count
和max
值未进行排序。
以下是视图的min
次调用:
sort
答案 0 :(得分:1)
您需要将要允许排序的字段列入白名单,如:Pagination
public $paginate = [
'sortWhitelist' => [
'id', 'title', 'Users.username', 'created'
]
];
否则默认情况下,蛋糕3阻止它