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 ...
随机推荐
- (转)solr排序OOM解决方法
转自 http://topcat.iteye.com/blog/1293650 问题 lucene使用排序时会将被排序字段全部加入内存再进行排序,当多次使用不同字段进行排序时会造成OOM问题 解决方案 ...
- tdx api z
调用TdxAPI.dll函数 .DLL命令 TdxInit, 逻辑型, "TdxApi.dll", "TdxInit", , 初始化通达信实例,成功时返回tru ...
- 重温delphi之:如何将Bitmap位图与base64字符串相互转换
先引用delphi自带的单元 uses EncdDecd; 然后就可以使用下面二个函数了: by 菩提树下的杨过 http://yjmyzz.cnblogs.com/ ///将Bitmap位图转化为b ...
- 【转】修改xampp的mysql默认密码
http://www.cnblogs.com/hongchenok/archive/2012/08/21/2648549.html MySQL 的“root”用户默认状态是没有密码的,所以在 PHP ...
- 设计模式_Iterator_迭代器模式
形象例子: 我爱上了Mary,不顾一切的向她求婚. Mary:“想要我跟你结婚,得答应我的条件” 我:“什么条件我都答应,你说吧” Mary:“我 ...
- maven 本地仓库的设置
设置方式一: 安装好maven后,在maven安装目录的conf文件夹下有一个settings.xml文件,该文件就是用来配置maven的一些常用参数 %MAVEN% / conf / setting ...
- TextView & EditText
TextView 1.下划线 textView.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG ); //下划线 2.单独做第一步,文字会出现锯齿,要加下 ...
- ACCESS-如何多数据库查询(跨库查询)
测试通过:ACCESSselect * from F:\MYk.mdb.tablename说明:1.查询语句2.来原于哪(没有密码是个路径)3.查询的表名 ====================== ...
- 第二十章、启动流程、模块管理与 Loader grub
Boot Loader: Grub 『 boot loader 是加载核心的重要工具』!没有 boot loader 的话,那么 kernel 根本就没有办法被系统加载! boot loader 的两 ...
- swift 内存管理,WEAK 和 UNOWNED
因为 Playground 本身会持有所有声明在其中的东西,因此本节中的示例代码需要在 Xcode 项目环境中运行.在 Playground 中可能无法得到正确的结果. 不管在什么语言里,内存管理的内 ...