逃离CakePHP Paginate条件

分页查询:

$this->paginate = array(
            'conditions' => array(
               // 'Product.soft_delete NOT'    => 'on',
               // 'Product.product_status NOT' => 'inactive',
               // $conditions
               'Product.original_price <=' =>  77
            ),
            'recursive'  => 2,
           // 'order'      => $sort_by,
            'paramType'  => 'querystring',
            'limit'      => '25',
            'maxLimit'   => 100,
        );
        $records = $this->paginate('Product');

CakePHP将单引号添加到original_price 77,因此它在数字比较中产生问题.

Cakephp查询输出:

............LEFT JOIN `admin_mytab`.`seller_categories` AS `Seller_3` ON (`Product`.`seller_3` = `Seller_3`.`id`) WHERE `Product`.`original_price` <= '77' LIMIT 25

MySQL original_price是varchar字段. 77引号无法与mysql字段进行比较.

任何帮助,将不胜感激.

最佳答案 尝试这样写:

$this->paginate = array(
    'conditions' => array(
        'Product.original_price <= 77'
    ),
    'recursive' => 2,
    'paramType' => 'querystring',
    'limit' => '25',
    'maxLimit' => 100,
);
$records = $this->paginate('Product');

而不是key =>价值只是使用价值.但通常,如果用引号括起数字也无关紧要,即使使用varchar也是如此.

点赞