我在cakephp3中使用分页组件进行排序
<?php echo $this->Paginator->sort('field');?>
在模特中,我加入了多个模型
$this->table('orders');
$this->primaryKey('order_id');
$this->hasMany('Customers');
$this->belongsTo('Customers', [
'foreignKey' => 'fk_customerid',
'joinType' => 'LEFT',
'dependent' => true,
]);
$this->hasMany('Users');
$this->belongsTo('Users', [
'foreignKey' => 'fk_userid',
'joinType' => 'LEFT',
'dependent' => true,
]);
在控制器中 - &gt;公共职能指数有
$getOrders = $this->Orders->find('all')
->contain([
'Customers' => function ($q) {
return $q
->select(['customer_name']);
},
'Users' => function ($q) {
return $q
->select(['firstname','lastname']);
}
])
->limit($this->per_page);
然后,如何使用paginate component.thanks
设置客户名称的排序答案 0 :(得分:1)
在cakephp3中,关联模型排序在控制器中使用'sortWhitelist':
$this->paginate = ['sortWhitelist' => [comma seprated names of your fiels],'limit' =>give pagelimit];
$this->set('getorder', $this->paginate($getOrders));