Paginator
Paginator
There are several ways to paginate items. The simplest is by using the paginate method on the query builder.
Paginating Database Results
$users = DB::table('users')->paginate(15);
The argument passed to the paginate method is the number of items you wish to display per page. Once you have retrieved the results, you may display them on your view, and create the pagination links using the links method:
<div class="container">
<?php foreach ($users as $user): ?>
<?php echo $user->name; ?>
<?php endforeach; ?>
</div>
<?php echo $users->links(); ?>
You may also access additional pagination information via the following methods:
- getCurrentPage
- getLastPage
- getPerPage
- getTotal
- getFrom
- getTo
- count
"Simple Pagination"
If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:
$someUsers = DB::table('users')->where('votes', '>', 100)->simplePaginate(15);
Creating A Paginator Manually
Sometimes you may wish to create a pagination instance manually, passing it an array of items. You may do so using the Paginator::make method:
$paginator = Paginator::make($items, $totalItems, $perPage);
Appending To Pagination Links
You can add to the query string of pagination links using the appends method on the Paginator:
<?php echo $users->appends(array('sort' => 'votes'))->links(); ?>
This will generate URLs that look something like this:
http://example.com/something?page=2&sort=votes
If you wish to append a "hash fragment" to the paginator's URLs, you may use the fragment method:
<?php echo $users->fragment('foo')->links(); ?>
This method call will generate URLs that look something like this:
http://example.com/something?page=2#foo
Full Example Usage
Users Model
namespace App\Models;
use Database\Model;
class Users extends Model
{
/**
* The table associated with the Model.
*
* @var string
*/
protected $table = 'users';
/**
* The primary key for the Model.
*
* @var string
*/
protected $primaryKey = 'id';
/**
* The number of Records to return for pagination.
*
* @var int
*/
protected $perPage = 25;
}
Users Controller
namespace App\Controllers;
use Core\View;
use Core\Controller;
class Users extends Controller
{
private $model;
public function __construct()
{
parent::__construct();
$this->model = new \App\Models\Users();
}
public function dashboard()
{
$users = $this->model->paginate();
return View::make('Users/Dashboard')
->shares('title', 'Dashboard')
->with('users', $users);
}
}
Users Dashboard View
<?php foreach ($users->getItems() as $user): ?>
<?php echo $user->username; ?>
<?php endforeach ?>
<?php echo $users->links() ?>
Paginator的更多相关文章
- bootstrap分页插件--Bootstrap Paginator的使用&AJAX版备份(可单独使用)
html部分: <ul class="pagination"></ul> <!--bootstrap3版本用ul包裹--> <div cl ...
- Bootstrap Paginator 分页插件参数介绍及使用
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...
- Bootstrap Paginator分页插件的使用
今天,我为大家带来的一款做得非常优秀的分页插件BootStrap Paginator,他是一款js插件,由于本人也是才刚刚搞出来的,所以暂时对它也不是特别了解,只能大楖告诉大家怎么使用.我这里使用的是 ...
- Bootstrap-分页插件Paginator
Bootstrap Paginator是一款基于Bootstrap的js分页插件,功能很丰富,个人觉得这款插件已经无可挑剔了.它提供了一系列的参数用来支持用户的定制,提供了公共的方法可随时获得插件状态 ...
- bootstrap paginator 与 bootstrap3兼容
bootstrap paginator可支持bootstrap2 和bootstrap3. 默认的下载包中支持2,需要手动修改才能支持bootstrap3.具体方法:找到bootstrap-pagin ...
- Bootstrap Paginator分页插件
Bootstrap Paginator分页插件使用示例 最近做的asp.netMVC项目中需要对数据列表进行分类,这个本来就是基于bootstrap开发的后台,因此也就想着bootstrap是否有分页 ...
- CakePHP下使用paginator需要对多个字段排序的做法
原文:http://blog.csdn.net/kunshan_shenbin/article/details/7644603 CakePHP下使用paginator需要对多个字段排序的做法 2 ...
- Django中扩展Paginator实现分页
Reference:https://my.oschina.net/kelvinfang/blog/134342 Django中已经实现了很多功能,基本上只要我们需要的功能,都能够找到相应的包.要在Dj ...
- Bootstrap Paginator分页插件+ajax 实现动态无刷新分页
之前做分页想过做淘宝的那个,但是因为是后台要求不高,就Bootstrap Paginator插件感觉还蛮容易上手,所以就选了它. Bootstrap Paginator分页插件下载地址: Downlo ...
随机推荐
- 【转】 Android中退出程序的提示框
原文网址:http://blog.csdn.net/jumping_android/article/details/7571309 @Override public boolean onKeyDown ...
- CSS遮罩——如何在CSS中使用遮罩
Css遮罩是2008年4月由苹果公司添加到webkit引擎中的.遮罩提供一种基于像素级别的,可以控制元素透明度的能力,类似于png24位或png32位中的alpha透明通道的效果. 图像是由rgb三个 ...
- CSLA的项目结构(一)
由于我也是边看边学,在很多概念不是很清晰的情况下,也不好将书中的大段内容全部摘抄过来,所以结合项目源码先分析再总结,就成目前比较可行方案,第一篇先从项目结构入手. 项目源码下载后,主要的功能集中在Co ...
- Mac 中查看端口占用进程并杀死
sudo lsof -i :9000 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME java 61342 a 313u IPv6 0x11111 ...
- cocos2d-x编译到android平台后,增加返回键和菜单键支持
在头文件中增加函数 virtual void keyBackClicked();//android返回键 virtual void keyMenuClicked();//android菜单键 在ini ...
- 关于SQL语言,查询关联多张表出现的,无法返回空值的问题。
用外连接: SELECT * from PERempms left outer join PERPROMSon PERPROMS.BRANCH =PERempms.BRANCH left outer ...
- sql-表值函数tvf
带有参数的视图 create function fn_fenye (@count as int,@page as int) returns table as return select * from ...
- 【原创】setjmp longjump一些注意点及使用方法
setjmp longjump一些注意点及使用方法 jmp_buf结构体的定义 #define _JBLEN 9typedef struct { int _jb[_JBLEN + 1]; } jmp ...
- Barcode記錄
.net開源框架 Barcode Rendering Framework URL:http://barcoderender.codeplex.com/releases/view/91902 可產生BR ...
- 转载 ASP.NET常用的正则表达式
转载原地址: http://www.cnblogs.com/0001/archive/2010/01/26/1656677.html 常用表达式: "^\d+$" //非负整数(正 ...