蛋糕PHP在Paginate中使用条件和顺序

时间:2015-04-24 09:48:58

标签: pagination cakephp-2.0

我正在尝试在Paginator助手的蛋糕PHP分页功能中使用条件和顺序

这是我正在使用的代码

$this->set('equipment', $this->Paginator->paginate('Equipment',array('conditions' => array('Equipment.equipment_type_id' => 19), 'order' => array('Equipment.problem_count', 'Equipment.barcode DESC'))));

但它给了我这个错误

错误:SQLSTATE [42S22]:找不到列:1054'where子句'中的未知列'条件'

SQL查询:SELECT EquipmentidEquipmentequipment_type_idEquipmentbarcodeEquipment。{ {1}},problem_countEquipmentdescriptionEquipmentcreatedEquipmentmodified。{{1 },EquipmentTypeidEquipmentTypenameEquipmentTypecreated FROM EquipmentTypemodified AS unlibike LEFT JOIN equipmentEquipment AS unlibike ON(equipment_typesEquipmentType = Equipmentequipment_type_id )WHERE条件=(19)AND EquipmentType IN('Equipment.problem_count','Equipment.barcode DESC')LIMIT 20

通过查看生成的SQL查询,看起来Cake PHP正在将“条件”和“订单”解释为列。

任何人都可以帮助我吗?

1 个答案:

答案 0 :(得分:1)

按Paginator :: paginate

的顺序排列
* @param Model|string $object Model to paginate (e.g: model instance, or 'Model', or 'Model.InnerModel')
* @param string|array $scope Additional find conditions to use while paginating
* @param array $whitelist List of allowed fields for ordering. This allows you to prevent ordering
 *   on non-indexed, or undesirable columns. See PaginatorComponent::validateSort() for additional details
 *   on how the whitelisting and sort field validation works.

http://api.cakephp.org/2.6/class-PaginatorComponent.html#_paginate

示例:

$this->Paginator->settings = array(
        'order'=>array('yourfields');
);

$this->Pagniator->paginate('Equipment', $conditionsArray ) ;