$v = array(1,11.38,15.8);
$sortByPrice = $this->Product->query
(
"SELECT *,
CASE `Product`.`currency`
WHEN '1' THEN $v[0]
WHEN '2' THEN $v[1]
WHEN '3' THEN $v[2]
END AS 'ratio'
FROM `products` AS `Product`
LEFT JOIN `marks` AS `Mark` ON (`mark_id` = `Mark`.`id`)
LEFT JOIN `categories` AS `Category` ON (`category_id` = `Category`.`id`)
RIGHT JOIN `photos` AS `Photo` ON (`Photo`.`product_id` = `Product`.`id`)
ORDER BY price*ratio DESC"
);
如何对此查询进行分页?我在book.cake上读过,但它没有解释得很好
答案 0 :(得分:0)
在这种情况下,如果您当前的页面与Product相对应 比起cakephp 3简直就是这样:
$this->paginate($sortByPrice);
$this->set(compact('$sortByPrice'));
正如之前的评论所说,最好使用cakephp的内置查询功能