我试图实现像sphinx文档这样的视图,你可以点击next和previous来在页面之间导航。不确定我是否在阵列右侧使用自定义分页器,我无法获得页面导航链接以显示在视图页面上。这是代码:
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]);
});
在视图中我调用了{!! $paginated->render() !!}
,但没有显示导航链接。
答案 0 :(得分:0)
以下是我在应用程序中处理自定义分页的方法(Laravel 5.1)。我创建了部分视图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
在我的控制器中,我通过了通常的$model->paginate(10)
方法。最后在我看来我想使用Paginator,resources/views/list.blade.php
我这样做:
@foreach ($objects as $object)
// Here we list the object properties
@endforeach
@include("partials.pagination", ['paginator' => $objects])