我的控制器中有一个自定义查询,我想实现我在cakephp.org上找到的自定义查询分页,但它们的示例与我的示例不同。有人能帮我在我看来把这个结果分页吗:

    $cars = $this->Car->query(" select Car.id, Car.make, Car.model, Car.year, Car.description, CarImage.thumbnail
                                    from cars Car
                                    inner join car_images CarImage on Car.default_image_id = CarImage.id
                                    where Car.make like '" . $category . "'
                                    order by Car.created DESC
                                    limit 10");
    $this->set('cars', $cars);

最佳答案

在模型中实现分页和分页计数:

function paginate($conditions, $fields, $order, $limit, $page, $recursive, $extra)
{
    return $this->query('SELECT ...');
}

function paginateCount($conditions, $recursive, $extra)
{
    return $this->query('SELECT COUNT(.....');
}

还可以查看cake/libs/controller/controller.php中的paginate函数

关于mysql - 自定义查询分页Cakephp,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/1850538/

10-09 08:23
查看更多