本文實(shí)例講述了Laravel框架自定義分頁(yè)樣式操作。分享給大家供大家參考,具體如下:
操作步驟如下:
(1) 對(duì)應(yīng)public/css/paging.css 文件建立分頁(yè)樣式.
(2) 控制器查出分頁(yè)數(shù)據(jù)使用 paginate函數(shù)進(jìn)行分頁(yè)處理.(禁止使用group by處理查詢).
(3) 對(duì)應(yīng)視圖引入分頁(yè)樣式.
例如: paging.css 樣式文件代碼(復(fù)制即可用,實(shí)際操作過)如下
#pull_right{
text-align:center;
}
.pull-right {
/*float: left!important;*/
}
.pagination {
display: inline-block;
padding-left: 0;
margin: 20px 0;
border-radius: 4px;
}
.pagination > li {
display: inline;
}
.pagination > li > a,
.pagination > li > span {
position: relative;
float: left;
padding: 6px 12px;
margin-left: -1px;
line-height: 1.42857143;
color: #428bca;
text-decoration: none;
background-color: #fff;
border: 1px solid #ddd;
}
.pagination > li:first-child > a,
.pagination > li:first-child > span {
margin-left: 0;
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.pagination > li:last-child > a,
.pagination > li:last-child > span {
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.pagination > li > a:hover,
.pagination > li > span:hover,
.pagination > li > a:focus,
.pagination > li > span:focus {
color: #2a6496;
background-color: #eee;
border-color: #ddd;
}
.pagination > .active > a,
.pagination > .active > span,
.pagination > .active > a:hover,
.pagination > .active > span:hover,
.pagination > .active > a:focus,
.pagination > .active > span:focus {
z-index: 2;
color: #fff;
cursor: default;
background-color: #428bca;
border-color: #428bca;
}
.pagination > .disabled > span,
.pagination > .disabled > span:hover,
.pagination > .disabled > span:focus,
.pagination > .disabled > a,
.pagination > .disabled > a:hover,
.pagination > .disabled > a:focus {
color: #777;
cursor: not-allowed;
background-color: #fff;
border-color: #ddd;
}
.clear{
clear: both;
}
例如:TestCntroller.php 控制器示例寫法
?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
class TestController extends Controller{
/**
* 測(cè)試數(shù)據(jù)
*/
public function index()
{
$test = DB::table('test')->paginate(5);
return view('index', ['test' => $test]);
}
}
例如: list.blade.php 視圖文件代碼示例寫法
!--用于引用css-->
link rel="stylesheet" type="text/css" href="{{asset('css/paging.css')}}" rel="external nofollow" />
div class="container">
!--查數(shù)據(jù)-->
@foreach ($test as $value)
{{ $value->id }}
@endforeach
/div>
div id="pull_right">
!--分頁(yè)寫法-->
div class="pull-right">
{{ $test->render() }}
/div>
/div>
樣式如下圖:
更多關(guān)于Laravel相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Laravel框架入門與進(jìn)階教程》、《php優(yōu)秀開發(fā)框架總結(jié)》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家基于Laravel框架的PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- Laravel5.5 手動(dòng)分頁(yè)和自定義分頁(yè)樣式的簡(jiǎn)單實(shí)現(xiàn)
- PHP框架Laravel插件Pagination實(shí)現(xiàn)自定義分頁(yè)
- laravel自定義分頁(yè)效果
- laravel自定義分頁(yè)的實(shí)現(xiàn)案例offset()和limit()
- laravel實(shí)現(xiàn)分頁(yè)樣式替換示例代碼(增加首、尾頁(yè))
- Laravel手動(dòng)分頁(yè)實(shí)現(xiàn)方法詳解
- Laravel+jQuery實(shí)現(xiàn)AJAX分頁(yè)效果
- Laravel框架執(zhí)行原生SQL語(yǔ)句及使用paginate分頁(yè)的方法
- laravel手動(dòng)創(chuàng)建數(shù)組分頁(yè)的實(shí)現(xiàn)代碼