Heim  >  Artikel  >  Backend-Entwicklung  >  Laravel 5.1 如何手动分页?

Laravel 5.1 如何手动分页?

WBOY
WBOYOriginal
2016-06-06 20:26:181122Durchsuche

现取到的数据是一个数组,想在模板页面分页。查了一些资料写的很是模糊。
官方文档好像也没有具体的方法,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>

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

回复内容:

现取到的数据是一个数组,想在模板页面分页。查了一些资料写的很是模糊。
官方文档好像也没有具体的方法,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>

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

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

EDIT

<code>class Paginator

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

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

<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>
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn