Laravel的Illuminate分页器无法找到查询字符串 [英] Laravel's Illuminate paginator can't find query string

查看:72
本文介绍了Laravel的Illuminate分页器无法找到查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在处理一个旧的PHP项目,该项目在旧版SQL查询中运行,这很好,但是我喜欢使用Laravel Illuminate SQL程序包之类的查询构建器!

I'm working on a old PHP project, that is running in legacy SQL query, which is good but I like to use query builders like Laravel Illuminate SQL package!

因此,我已经添加了运行Illuminate SQL所需的所有程序包依赖关系,并且此查询构建器似乎可以在分页中正常工作!

So i have added all required package dependencies to run Illuminate SQL, and this query builder seems to work fine with pagination!

$users = Capsule::table('users')->paginate(1)->toArray();

但是,分页器似乎无法收听查询字符串!例如,通过运行上面的代码,它将提供一些属性,例如next_page,previous_page等...

But, the paginator seems not to be able to listen the query string! For example, by running the above code it would give some properties like, next_page , previous_page etc...

当我尝试在 URL 中传递查询字符串时,它无法从查询字符串中获取数据(来自 GET 请求)!

And when I try to pass the query string in the URL it can't fetch the data from query string(From the GET request)!

访问此页面 http://app.app/?page=2 会得到相同的结果集.

Visiting this page http://app.app/?page=2 would give the same result set.

我应该如何配置Illuminate sql程序包,使其也可以侦听查询字符串?

How i should configure the Illuminate sql package so it can also listen to the query strings?

编辑

此外,我尝试使用 illuminate/http 包,但是 $ request-> all()方法始终返回一个空数组!这是代码:

Also, i've tried to use the illuminate/http package, but the $request->all() method always returns an empty array! Here is the code:

<?php
  require_once './vendor/autoload.php';
  use \Illuminate\Http\Request;

  $req = new Request();

  echo '<pre>';
  print_r($req->all());
  echo '</pre>';

它返回空的输入数据数组,

It returns empty input data array,

我缺少使用http软件包的内容,任何想法都会有所帮助.

What i am missing to use the http package, any idea would be helpful.

推荐答案

您必须设置页面解析器:

You have to set a page resolver:

\Illuminate\Pagination\Paginator::currentPageResolver(function ($pageName = 'page') {
    return (int) ($_GET[$pageName] ?? 1);
});

Laravel使用解析器.

Laravel uses this resolver.

这篇关于Laravel的Illuminate分页器无法找到查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆