本文實(shí)例講述了Laravel框架自定義分頁樣式操作。分享給大家供大家參考,具體如下:
操作步驟如下:
(1) 對應(yīng)public/css/paging.css 文件建立分頁樣式.
(2) 控制器查出分頁數(shù)據(jù)使用 paginate函數(shù)進(jìn)行分頁處理.(禁止使用group by處理查詢).
(3) 對應(yīng)視圖引入分頁樣式.
例如: 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{
/**
* 測試數(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">
!--分頁寫法-->
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è)計入門教程》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對大家基于Laravel框架的PHP程序設(shè)計有所幫助。
您可能感興趣的文章:- Laravel5.5 手動分頁和自定義分頁樣式的簡單實(shí)現(xiàn)
- PHP框架Laravel插件Pagination實(shí)現(xiàn)自定義分頁
- laravel自定義分頁效果
- laravel自定義分頁的實(shí)現(xiàn)案例offset()和limit()
- laravel實(shí)現(xiàn)分頁樣式替換示例代碼(增加首、尾頁)
- Laravel手動分頁實(shí)現(xiàn)方法詳解
- Laravel+jQuery實(shí)現(xiàn)AJAX分頁效果
- Laravel框架執(zhí)行原生SQL語句及使用paginate分頁的方法
- laravel手動創(chuàng)建數(shù)組分頁的實(shí)現(xiàn)代碼