首页 > 编程语言 > 详细

laravel 框架给数组分页

时间:2017-09-17 12:19:52      阅读:291      评论:0      收藏:0      [点我收藏+]

        //Get current page form url e.g. &page=6
        $currentPage = LengthAwarePaginator::resolveCurrentPage();

        $currentPage -= 1;

        //Create a new Laravel collection from the array data
        $collection = new Collection($log_data[‘content‘]);

        //Define how many items we want to be visible in each page
        $perPage = 10;

        //Slice the collection to get the items to display in current page
        $currentPageSearchResults = $collection->slice($currentPage * $perPage, $perPage)->all();

        //Create our paginator and pass it to the view
        $paginatedSearchResults= new LengthAwarePaginator($currentPageSearchResults, count($collection), $perPage);

        $url = url(‘admin/statistics/index‘);

        $paginatedSearchResults = $paginatedSearchResults->setPath($url);

laravel 框架给数组分页

原文:http://www.cnblogs.com/handongyu/p/7535067.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!