Home  >  Article  >  Backend Development  >  php Laravel 框架之分页

php Laravel 框架之分页

WBOY
WBOYOriginal
2016-06-23 13:56:261160browse

今天学习了Laravel的分页功能,感觉它这个非常的好用.
下面拿出来和大家分享一下.
首先第一步,我们需要获取到查询的结果.
方法大家应该各有所异,无非包括各种条件,排序.但是最后我们必须通过
paginate(PAGESIZE)来获取选定的结果.
例如:我使用Eloquent 来获取数据.
$ret = User::where('age','gt',25)->orderBy('sex','asc')->paginate();
好了,我们需要将它们带入视图当中.
return View::make('user.index')->with('results',$ret);

//这里需要解释一下,这里的user.index表示的是 在views文件夹下的user文件夹下的index.blade.php
视图模板文件.
学过Laravel的都明白呵.
在index.blade.php中.
我们通过模板循环输出.

例如

   

   

   

   

@foreach($results as $v)

   

   

   

   

@endforeach

   

id name sex Action
{{$v->id}} {{$v->name}} {{$v->sex}} action
{{$results->links()}}

好了,这里最关键的就是我们的tfoot里面的内容了...

它能够自动生成我们的分页.

这里我们要注意一点.

最终生成的连接如 http://localhost/party/public/notice?page=2

这样我们就能够正常的进行翻页操作了.


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn