Home > Backend Development > PHP Tutorial > Laravel 5.1 如何手动分页?

Laravel 5.1 如何手动分页?

WBOY
Release: 2016-06-06 20:26:18
Original
1196 people have browsed it

现取到的数据是一个数组,想在模板页面分页。查了一些资料写的很是模糊。
官方文档好像也没有具体的方法,http://laravel.com/docs/5.1/pagination#manually-creating-a-paginator

所以想问下各位有木有遇到过类似的问题,能不能提供点方法。

使用

<code>$page = (Input::get('page')) ? Input::get('page') : 1;

$paginator = new Paginator($articles, count($articles), 2,$page);</code>
Copy after login
Copy after login

分页出来了,不过内容不是分页的数据该咋办?

回复内容:

现取到的数据是一个数组,想在模板页面分页。查了一些资料写的很是模糊。
官方文档好像也没有具体的方法,http://laravel.com/docs/5.1/pagination#manually-creating-a-paginator

所以想问下各位有木有遇到过类似的问题,能不能提供点方法。

使用

<code>$page = (Input::get('page')) ? Input::get('page') : 1;

$paginator = new Paginator($articles, count($articles), 2,$page);</code>
Copy after login
Copy after login

分页出来了,不过内容不是分页的数据该咋办?

$paginator = Paginator::make($products, $totalCount, $perPage);

EDIT

<code>class Paginator

public function __construct($items, $perPage, $currentPage = null, array $options = [])</code>
Copy after login
<code>$html = $paginator->render();</code>
Copy after login

给个实例给你,用的是数组
给个实例给你,用的是数组

<code>$page=1;
        if($request->input('page'))
        {
            $page=$request->input('page');
        }
        $pagesize=2;
        $total=count($pagedata);
        $pages=ceil($total/$pagesize);
        //这里前面引入命名类,如果没有引入,可以这样做
        new Illuminate\Pagination\LengthAwarePaginator($pagedata,$total,$pagesize);
        
        $paged=new LengthAwarePaginator($pagedata,$total,$pagesize);
        $paged=$paged->setPath(route('admin.wxmenu.index'));
        $pageout=array_slice($pagedata, ($page-1)*$pagesize,$pagesize);
        foreach ($pageout as $v)
        {
            echo $v['title']."<br>";

        }
        echo $paged->links();</code>
Copy after login
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template