0
    $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 上读过,但解释得不是很好

4

1 回答 1

0

在这种情况下,如果您的当前页面对应于 Product 而不是在 cakephp 3 中看起来像这样:

$this->paginate($sortByPrice);
$this->set(compact('$sortByPrice'));

正如前面的评论所说,最好使用 cakephp 的内置查询功能

于 2017-08-26T20:18:18.127 回答