PHP-Phalcon:如何获取结果集和总数超出限制
作者:互联网
如何使用查询生成器(最佳方法)在Phalcon中实现此查询:
$results = "select * from table where name like 'A%' limit 10"; // <-- 10 records
$total = "select count(1) from table where name like 'A%'"; // <-- 100 records
return [
'data' => $result,
'total' => $total
];
我是extjs用户,我需要获得总计超出限制才能显示分页信息(例如:从100条记录中显示1到10)
谢谢.
解决方法:
您可以通过分页实现此目的,请参见此处:Pagination Docs
唯一的事情就是使用QueryBuilder适配器.但这可以通过以下方式完成:
$builder = $this->modelsManager->createBuilder()
->from('Table')
->andWhere('name like :name:', array('name' => 'A%' ) );
$paginator = new Phalcon\Paginator\Adapter\QueryBuilder(array(
"builder" => $builder,
"limit"=> 10,
"page" => 1
));
return [
'data' => $paginator->items,
'total' => $paginator->total_items
];
标签:phalcon,php 来源: https://codeday.me/bug/20191121/2053684.html