简体   繁体   English

laravel 5自定义分页器不起作用

[英]laravel 5 custom paginator not working

im trying to implement a view like sphinx documentation where you can click on next and previous to navigate between pages. 我试图实现像狮身人面像文档这样的视图,您可以单击下一个和上一个在页面之间导航。 not sure if im using the custom paginator on array right, i cant get page navigation links to display on a view page. 不知道即时消息是否在数组右边使用自定义分页器,我无法获取页面导航链接以在视图页面上显示。 this is the code: 这是代码:

   public function paginate($array, $perPage, $pageStart=1) {

    $offset = ($pageStart * $perPage) - $perPage;

    return new Paginator(array_slice($array, $offset, $perPage, true), $perPage, $pageStart);
   }

   view()->composer('layouts.book', function($view)
   {
        //some other code
        $pages = [];
        foreach($book->textsection_pages as $textsection) {
            $pages[] = $textsection->alias;
        }
        foreach($book->task_pages as $task) {
            $pages[] = $task->alias;
        }
        foreach($book->tutor_pages as $tutor) {
            $pages[] = $tutor->alias;
        }
        foreach($book->eval_pages as $eval) {
            $pages[] = $eval->alias;
        }

        $chapters = $book->chapters()->orderBy('weight', 'asc')->get();
        $paginated = $this->paginate($pages, 1);
        $view->with(['chapters' => $chapters, 'book' => $book, 'paginated' => $paginated]);

    });

and in the view i called {!! $paginated->render() !!} 在我看来,我叫{!! $paginated->render() !!} {!! $paginated->render() !!} , but no navigation link was displayed. {!! $paginated->render() !!} ,但未显示导航链接。

Here is how I handle custom Pagination in my application (Laravel 5.1). 这是我在应用程序(Laravel 5.1)中处理自定义分页的方法。 I create a partial view resources/views/partials/pagination.blade.php 我创建了一个局部视图resources/views/partials/pagination.blade.php

@if ($paginator->lastPage() > 1)
<ul id="pagination">
    <li>
    @if ($paginator->currentPage() > 1)
        <a class="prev" href="{{ $paginator->url($paginator->currentPage()-1) }}">Previous</a>
    @else
        <span class="disabled">Previous</span>
    @endif
    </li>

    <li>
    @if ($paginator->currentPage() !== $paginator->lastPage())
        <a class="next" href="{{ $paginator->url($paginator->currentPage()+1) }}" >Next</a>
    @else
        <span class="disabled">Next</span>
    @endif
    </li>
</ul>
@endif

In my controller, I pass the usual $model->paginate(10) method. 在我的控制器中,我通过了通常的$model->paginate(10)方法。 Then finally in my view where I want to use the Paginator, resources/views/list.blade.php I do this: 然后最后在我要使用Paginator的视图中, resources/views/list.blade.php我这样做:

@foreach ($objects as $object)
    // Here we list the object properties
@endforeach
@include("partials.pagination", ['paginator' => $objects])

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM