本文介绍了自定义查询分页 Cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的控制器中有一个自定义查询,我想实现我在 cakephp.org 上找到的自定义查询分页,但他们的示例与我的不同.有人可以帮我在我看来分页这个结果:
I have a custom query in my controller and I would like to implement the custom query pagination I found on cakephp.org but their example is not similar to mine. Can someone please help me paginate this result in my view:
$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);
推荐答案
在你的模型中实现 paginate 和 paginateCount:
Implement paginate and paginateCount in your model:
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中的分页功能
Also check out the paginate function in: cake/libs/controller/controller.php
这篇关于自定义查询分页 Cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!