首页 > 代码库 > phalcon几种分页方法
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 ));
phalcon几种分页方法
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。