laravel·ÖÒ³Ôõô¼Ócss
laravelÊÇÒ»¸ö¹ãÊܽӴýµÄphp¿ò¼Ü£¬ÒòÆäÒ×ÓÚѧϰ¡¢Ê¹Óá¢À©Õ¹£¬ÒÔ¼°°üÀ¨Ç¿Ê¢µÄ¹¦Ð§¶ø±¸ÊÜÍÆÐí¡£ÆäÖУ¬·ÖÒ³ÊÇwebÓ¦ÓóÌÐòÖбز»¿ÉÉٵĹ¦Ð§Ö®Ò»¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚlaravelÖÐʵÏÖ·ÖÒ³²¢Ìí¼ÓcssÑùʽ¡£
Ò»¡¢LaravelÖÐʵÏÖ·ÖÒ³
ÔÚLaravel¿ò¼ÜÖУ¬·ÖÒ³ÊÇͨ¹ýPaginatorÀàʵÏֵġ£PaginatorÀàʹÓÃQuery Builder»òEloquent ORM´ÓÊý¾Ý¿â»ñÈ¡Êý¾Ý£¬²¢»ùÓÚÒ³¾ÞϸºÍÄ¿½ñÒ³Âë¶ÔЧ¹û¾ÙÐзÖÒ³¡£Ïêϸ°ì·¨ÈçÏ£º
ÒýÈëPaginatorÀà
use Illuminate\Pagination\Paginator;
µÇ¼ºó¸´ÖÆ
¼ìË÷Êý¾Ý
$data = DB::table('table_name')->paginate(5);
µÇ¼ºó¸´ÖÆ
»ò
$data = ModelName::paginate(5);
µÇ¼ºó¸´ÖÆ
ÏÔʾÊý¾Ý
@foreach ($data as $item) // @endforeach {{ $data->links() }}
µÇ¼ºó¸´ÖÆ
ÒÔÉÏ´úÂ뽫¼ìË÷ÃûΪ¡°table_name¡±µÄ±íµÄÊý¾Ý£¬½«Ã¿¸öÒ³ÃæÖеļͼÊýÉèÖÃΪ5£¬²¢½«Æä´æ´¢ÔÚÃûΪ¡°data¡±µÄ±äÁ¿ÖС£ÔÚÊÓͼÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýforeachÑ»·±éÀúÊý¾Ý£¬²¢Í¨¹ý$data->links()ÒªÁìÉúÒòËØÒ³Á´½Ó¡£
Á¬Ã¦Ñ§Ï°¡°Ç°¶ËÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
¶þ¡¢LaravelÖÐÌí¼ÓCSSÑùʽ
LaravelΪ·ÖÒ³Á´½ÓÌṩÁËĬÈϵÄÑùʽ¡£¿ÉÊÇ£¬ÎÒÃÇ¿ÉÒÔͨ¹ý×Ô½ç˵CSSÀ´¸Ä±äÆäÍâ¹Û¡£ÈôÊÇÄúÏë½ûÓÃĬÈÏÑùʽ£¬¿ÉÒÔͨ¹ýÒÔÏ´úÂëʵÏÖ£º
{{ $data->links('') }}
µÇ¼ºó¸´ÖÆ
ÒÔÏÂÊÇ×Ô½ç˵CSSÑùʽµÄ°ì·¨£º
ÔÚpublic/cssĿ¼Öн¨ÉèÒ»¸öеÄCSSÎļþ£¬Èç¡°pagination.css¡±¡£
ÔÚÊÓͼÖУ¬Í¨¹ýÔÚhead±êÇ©ÖÐÒýÈëCSSÎļþ£º
<link>
µÇ¼ºó¸´ÖÆ
ÔÚCSSÎļþÖÐÌí¼ÓÑùʽ
.pagination li { display:inline-block; margin-right:5px; margin-bottom:5px; padding:5px 12px; border:1px solid #ccc; border-radius:5px; font-size:14px; color:#333; text-decoration:none; } .pagination .active { background-color:#007bff; border-color:#007bff; color:#fff; } .pagination .disabled { opacity:0.5; cursor:not-allowed; }
µÇ¼ºó¸´ÖÆ
ÒÔÉÏÑùʽ½«Îª·ÖÒ³Á´½ÓÌí¼ÓÔ²½Ç±ß¿ò£¬ÉèÖÃ×ÖÌå¾ÞϸºÍÑÕÉ«£¬²¢ÎªÄ¿½ñÒ³Ìí¼ÓÌض¨Åä¾°ÑÕÉ«¡£
Èý¡¢×ܽá
ÔÚLaravel¿ò¼ÜÖÐʹÓÃPaginatorÀàʵÏÖ·ÖÒ³ºÜÊǼòÆÓ¡£¶ø¶¨ÖÆ»¯·ÖÒ³ÑùʽҲ²»ÊÇÌ«ÄÑ£¬Ö»ÐèÒªÌí¼ÓCSS´úÂë¼´¿É¡£Ï£Íû±¾ÎÄÄܶÔLaravel·ÖÒ³ºÍCSSÑùʽµÄʹÓÃÓÐËù×ÊÖú¡£ÈôÊÇÄúÓÐÈκÎÎÊÌâ»ò½¨Ò飬ÇëÔÚ̸ÂÛÇøÁôÑÔ£¬ÎÒÃǽ«ºÜÊÇÔ¸Òâ»Ø¸²ÄúµÄÎÊÌâ¡£
ÒÔÉϾÍÊÇlaravel·ÖÒ³Ôõô¼ÓcssµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡