【发布时间】:2017-03-16 16:50:13
【问题描述】:
这是我的分页代码:
控制器:
public function index($request, $response) {
$current_page = $request->getParam('page');
Paginator::currentPageResolver(function() use ($current_page) {
return $current_page;
});
$routes = $this->route->paginate(2);
return $this->view->render($response, 'dashboard/dashboard.twig', [
'routes' => $routes
]);
}
查看:
{% for route in routes %}
{{ route.route_name }}<br>
{% endfor %}
当我运行浏览器时,这没有问题。每当我在 url 中添加 page 参数时,它也可以工作。
但是当我尝试在分页对象中添加links 方法时。
{% for route in routes %}
{{ route.route_name }}<br>
{% endfor %}
{{ routes.links() }} {# <--- This one #}
它提示我一个错误
消息:在 null 上调用成员函数 make()
文件:C:\xampp\htdocs...\vendor\illuminate\pagination\LengthAwarePaginator.php
更新:
当我尝试在 Controller 中回显 links() 方法时。我发现了这个错误。
$routes = $this->route->paginate(5);
echo $routes->links();
die();
警告:call_user_func() 期望参数 1 是一个有效的回调,在 C:\xampp\htdocs...\vendor\illuminate\pagination\AbstractPaginator.php 第 377 行中没有给出数组或字符串
然后我查了源码,就是这个。
/**
* Get an instance of the view factory from the resolver.
*
* @return \Illuminate\Contracts\View\Factory
*/
public static function viewFactory()
{
return call_user_func(static::$viewFactoryResolver);
}
有什么解决办法吗?
此方法在5.2有效,参考此链接。
Pagination with Twig and Eloquent-5.2
但不幸的是,它不再起作用了。
【问题讨论】:
-
你找到 5.3 的解决方案了吗?
标签: php pagination eloquent