自定义查询分页Cakephp [英] Custom Query Pagination Cakephp
本文介绍了自定义查询分页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(.....');
}
同时检查paginate函数:cake / libs / controller / controller.php
Also check out the paginate function in: cake/libs/controller/controller.php
这篇关于自定义查询分页Cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文