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=votesIf 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#fooFull 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 ... 
随机推荐
- 【转】Windows搭建Eclipse+JDK+SDK的Android
			原文网址:http://blog.csdn.net/sunboy_2050/article/details/6336480 一 相关下载 (1) Java JDK下载: 进入该网页: http://j ... 
- ajax取json数据——简单的
			json数据:json4.json <!DOCTYPE html> <html> <head> <meta charset="utf-8" ... 
- (六)学习CSS之color属性
			参考:http://www.w3school.com.cn/cssref/pr_text_color.asp color 属性规定文本的颜色. 这个属性设置了一个元素的前景色(在 HTML 表现中,就 ... 
- 关于C#中static静态变量
			C#静态变量使用static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做非静态变量,在对象被实例化时创建,通过对象进行访问一个类的所有实例的同一C#静 ... 
- java jvm学习笔记一
			欢迎装载请说明出处:http://blog.csdn.net/yfqnihao java的class只在需要的时候才内转载入内存,并由java虚拟机的执行引擎来执行,而执行引擎从总的来说主要的执行方式 ... 
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
			UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ... 
- js  onchange事件
			因为onchange在属性值改变时还必须使得当前元素失去焦点(onblur)才可以激活该事件. 如果你需要即时监听输入框值的变化,建议使用 onpropertychange 事件! 在IE下,当一个H ... 
- HW6.1
			import java.util.Scanner; public class Solution { public static void main(String[] args) { Scanner i ... 
- Java 开发@ JDBC链接SQLServer2012
			下面请一字一句地看,一遍就设置成功,比你设置几十遍失败,费时会少得多. 首先,在连接数据库之前必须保证SQL Server 2012是采用SQL Server身份验证方式而不是windows身份验证方 ... 
- Android uiautomator实例使用
			转载自:http://blog.csdn.net/huiguixian/article/details/22398193 Android测试工具中,Monkey Runner只要简单几个指令即可,但他 ... 
