laravel 大å°ä¹ å页 模å_php_web-itnose
é¦é¡µ
asp
php
javascript
iis
apache
html/css
coldfusion
ajax
vbscript
cgi
xml/xsl
è·¨æµè§å¨å¼å
ruby/rails
ç¨åºå
html5
jquery
seo
jboss
json
angularjs
markdown
nginx
thinkphp
yii
pageadmin
extjs
wampserver
kendo ui
coffeescript
gulp
ecmascript
bootstrap
itnoseé¦é¡µ > web > php >
laravel 大å°ä¹ å页 模å
2017-06-13 14:45
ç®ä»
å页模åçåºæ¬ä½¿ç¨æ两ç§ï¼ä¸ç§æ¯åºäºæ¥è¯¢æ建å¨æeloquent模åï¼è°ç¨paginateæ¹æ³ï¼å¦ä¸ç§æ¯æå¨å建å页å¨ï¼
laravelæ¡æ¶çå页å¨ä¸ä» å®ç°äºæ°æ®çå页ï¼èä¸æ¯æçæbootstrapçå页æ¡ï¼å¦ä¸å¾æ示
使ç¨
åºäºæ¥è¯¢æ建å¨æeloquent模å
ä»user表è·åæ°æ®ï¼æ¯é¡µ16æ¡ï¼å¯ä»¥è¿æ ·å
$users = db::table(‘user’)->paginate(16);
// æ
$users = user::paginate(16);
è¿æ¶ç$useræ¯illuminate\pagination\lengthawarepaginatorå®ä¾ï¼è¿é没æä¼ éå½å页çåå æ¯ï¼å¦æä¸ä¼ éï¼ä¼ä»$request请æ±è·åå½å页ï¼paginateæ¹æ³å®æ´åæ°å®ä¹å¦ä¸ï¼
paginate($perpage = null, $columns = [‘*’], $pagename = ‘page’, $page = null)
å ¶ä¸ $perpage 代表æ¯é¡µæ¾ç¤ºæ°ç®ï¼ $columns 代表æ¥è¯¢åæ®µï¼ $pagename 代表页ç åç§°ï¼ $page 代表第å 页ã
åçï¼ä¹å¯ä»¥è·åå¦ä¸ç§å页ï¼ç®åå页
$users = db::table(‘user’)->simplepaginate(16);
// æ
$users = user::simplepaginate(16);
è¿æ¶ç$useræ¯illuminate\pagination\paginatorå®ä¾ï¼
è¦æ³å¨é¡µé¢åç°å页å¨çå°æ¹åï¼ åªè¦å¨blade.php ä¸ä¹¦å
{!! $users->render() !!}
æå¨å建
éè¿ççlaravelçdatabaseæ¯æä¹å®ç°å建å页å¨ï¼æ´å¥½å°å¦ä¼ä½¿ç¨æå¨å建ï¼å ççpaginateæ¹æ³ï¼
public function paginate($perpage = null, $columns = [‘*’], $pagename = ‘page’, $page = null)
{
// è·åå½å页æ°
$page = $page ?: paginator::resolvecurrentpage($pagename);
// è·åæ¯é¡µçæ°é
$perpage = $perpage ?: $this->model->getperpage();
// collectionç±»ï¼åæ¾å½å页çæ°æ®è®°å½
$results = ($total = $this->tobase()->getcountforpagination())
? $this->forpage($page, $perpage)->get($columns)
: $this->model->newcollection();
return new lengthawarepaginator($results, $total, $perpage, $page, [
// å½å页é¢ç url
‘path’ => paginator::resolvecurrentpath(),
‘pagename’ => $pagename,
]);
}
åççsimplepaginateæ¹æ³
public function simplepaginate($perpage = null, $columns = [‘*’], $pagename = ‘page’, $page = null)
{
// è·åå½å页æ°
$page = $page ?: paginator::resolvecurrentpage($pagename);
// è·åæ¯é¡µçæ°é
$perpage = $perpage ?: $this->model->getperpage();
// è°ç¨ database 模åå½åç±»çæ¹æ³ï¼è·åå½å页çæ°æ®ï¼
// ä¸é¢è¿ä¸ªè¯å¥åªæ¯è®¾ç½®æ¥è¯¢æ¡ä»¶ï¼get æ¹æ³è°ç¨æ¶ææ¯çæ£å»è·å
$this->skip(($page – 1) * $perpage)->take($perpage + 1);
return new paginator($this->get($columns), $perpage, $page, [
// å½å页é¢ç url
‘path’ => paginator::resolvecurrentpath(),
‘pagename’ => $pagename,
]);
}
ççæºä»£ç
æå¡æä¾è
serviceprovider
bootæ¹æ³
public function boot()
{
// 注åå
è§å¾
$this->loadviewsfrom(__dir__.’/resources/views’, ‘pagination’);
// å¦æç¨åºæ¯å¨å½ä»¤è¡ä¸è¿è¡ï¼åå°æ¨¡åå
ç`resources/views`æ件夹ä¸çæ件
// åå¸ä¸ä»½å°é¡¹ç®ç`views/vendor/pagination`æ件夹ï¼
// publishes æ¹æ³ç第äºä¸ªåæ°æ¯ group ç»ï¼
if ($this->app->runninginconsole()) {
$this->publishes([
__dir__.’/resources/views’ => $this->app->resourcepath(‘views/vendor/pagination’),
], ‘laravel-pagination’);
}
}
registeræ¹æ³
public function register()
{
// ç»å® view è§å¾è§£æå¨
paginator::viewfactoryresolver(function () {
return $this->app[‘view’];
});
// ç»å® url è·¯å¾è§£æå¨ï¼è¿åå½å url
paginator::currentpathresolver(function () {
return $this->app[‘request’]->url();
});
// ç»å® å½å页 解æå¨ï¼è¿åå½å页
paginator::currentpageresolver(function ($pagename = ‘page’) {
$page = $this->app[‘request’]->input($pagename);
if (filter_var($page, filter_validate_int) !== false && (int) $page >= 1) {
return $page;
}
return 1;
});
}
å页å¨ç±»æ两个paginatorålengthawarepaginatorï¼é½ç»§æ¿äºç¶ç±»abstractpaginator;两è ç主è¦åºå«ä¸»è¦å¨äºrenderæ¹æ³ï¼ä¹å°±æ¯åç°çbootstrapé£æ ¼çå页å¨ä¸ä¸æ ·ï¼
paginatorçå页å¨ï¼åªæä¸ä¸é¡µåä¸ä¸é¡µçå¾æ
lengthawarepaginatorçå页å¨
ç¸å
³æç´¢ï¼
vb.net 模å
jspå页
jsp å页
.net å页
hibernate å页
ç¸å ³æç«
2017-02-23 23:16 laravel å页seoæµ
è°
2016-12-20 09:53 laravelçæç´¢åå页
2016-02-06 08:43 [ laravel 5.2 ææ¡£ ] æå¡ — å页
2014-05-27 20:37 php laravel æ¡æ¶ä¹å页
2016-09-30 19:28 [ laravel 5.3 ææ¡£ ] æ°æ®åº — å页
æ´å¤ç¸å ³æç« >>
ææ°æç«
2017-06-20 01:35 èé们ï¼æ没æå¯è½è®©phpæ件åæ¶åªè½ä¸ä¸ªäººè®¿é®
2017-06-20 01:35 æä¹ç¦æ¢å¾çç´æ¥éè¿url访é®
2017-06-20 01:35 æ±æ!å¯å¨wampåªè½ç¨æ¬æºè®¿é®,åå±åç½çå
¶å®è®¾å¤è®¿é®ä¸å°!æäºå¤§å天t-t
2017-06-19 15:35 nginxä¸çthinkphpé®é¢
2017-06-19 15:35 php form æ件ä¸ä¼
æ´å¤ææ°æç« >>
çé¨æç´¢
hibernateå页
linq å页
linqå页
sqlserver å页
cè¯è¨æ¨¡ååç¼ç¨
jspå页ææ¯
jspå页æ¥è¯¢
hibernateå页æ¥è¯¢
hibernateå页代ç
javawebå页
asp.net å页
linqå页æ¥è¯¢
db2 å页
asp.net mvc å页
京icpå¤14022385å·-2
©2014 itnose软件ç¼ç¨æç¨ | èç³»æ们ï¼emailï¼twobrushes@126.com qq:35155868