phalcon几种分页方法

phalcon几种分页方法

一:

use Phalcon\Paginator\Adapter\Model as PaginatorModel;

// Current page to show
// In a controller this can be:
// $this->request->getQuery('page', 'int'); // GET
// $this->request->getPost('page', 'int'); // POST
$currentPage = (int) $_GET["page"]; // The data set to paginate
$robots = Robots::find(); // Create a Model paginator, show 10 rows by page starting from $currentPage
$paginator = new PaginatorModel(
array(
"data" => $robots,
"limit" => 10,
"page" => $currentPage
)
); // Get the paginated results
$page = $paginator->getPaginate();

  

二:

use Phalcon\Paginator\Adapter\Model as PaginatorModel;
use Phalcon\Paginator\Adapter\NativeArray as PaginatorArray;
use Phalcon\Paginator\Adapter\QueryBuilder as PaginatorQueryBuilder; // Passing a resultset as data
$paginator = new PaginatorModel(
array(
"data" => Products::find(),
"limit" => 10,
"page" => $currentPage
)
); // Passing an array as data
$paginator = new PaginatorArray(
array(
"data" => array(
array('id' => 1, 'name' => 'Artichoke'),
array('id' => 2, 'name' => 'Carrots'),
array('id' => 3, 'name' => 'Beet'),
array('id' => 4, 'name' => 'Lettuce'),
array('id' => 5, 'name' => '')
),
"limit" => 2,
"page" => $currentPage
)
); // Passing a QueryBuilder as data $builder = $this->modelsManager->createBuilder()
->columns('id, name')
->from('Robots')
->orderBy('name'); $paginator = new PaginatorQueryBuilder(
array(
"builder" => $builder,
"limit" => 20,
"page" => 1
)
);

  

基于模糊查找的分页:

 $builder = $this->modelsManager->createBuilder()
->columns("SysCustomer.cus_id,SysCustomer.man_id,SysCustomer.company_name,SysCustomer.contact_name,SysCustomer.mobile,SysCustomer.serv_status,
COUNT(DISTINCT SysCustApp.app_id ) as appcode_num,
COUNT(DISTINCT SysCustAppAirport.airport_code) as airport_num")
->from("SysCustomer")
->leftJoin("SysCustApp", "SysCustApp.cus_id = SysCustomer.cus_id")
->leftJoin("SysCustAppAirport", "SysCustAppAirport.cus_id = SysCustApp.cus_id");
if(!empty($param))
{
$builder ->where($where, array("company" => '%'.$param.'%', "contact"=>'%'.$param.'%', "mobile"=>'%'.$param.'%'));
}else{
$builder ->where($where);
}
$builder->groupBy("SysCustomer.cus_id"); $paginator = new PaginatorQueryBuilder(
array(
'builder'=>$builder,
'limit' =>10,
'page' =>$currentPage
)
);

  

上一篇:Mysql创建函数出错


下一篇:利用LogParser分析IIS日志