即時嘗試實現一個視圖,如獅身人面像文檔,您可以點擊下一頁和上一頁在頁面之間導航。不知道如果即時使用陣列上的自定義paginator權利,我不能得到頁面導航鏈接顯示在視圖頁面上。這是代碼:laravel 5自定義分頁程序不工作
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() !!}
,但不顯示導航鏈接。
有託運laravel 5 API,分頁程序的構造是'__construct(混合$項目,詮釋$總,詮釋$ perPage,INT | null $ currentPage = null,array $ options = array())' – yangqi
是的,我做過。它的'__construct($ items,$ perPage,$ currentPage = null,array $ options = [])' –
啊,我看到這是因爲你在一個閉包中調用了paginate()方法,'$ this'沒有引用去上課。 – yangqi