laravel 如何更改 Paginator 的页面名称?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22731024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do you change the page name for Paginator?
提问by Marwelln
Current Paginatoris using ?page=N, but I want to use something else. How can I change so it's ?sida=Ninstead?
当前Paginator正在使用?page=N,但我想使用其他东西。我怎样才能改变它?sida=N呢?
I've looked at Illuminate\Pagination\Environmentand there is a method (setPageName()) there to change it (I assume), but how do you use it?
我看过了Illuminate\Pagination\Environment,有一种方法 ( setPageName()) 可以改变它(我假设),但是你如何使用它?
In the Paginatorclass there is a method the change the base url (setBaseUrl()) in the Environmentclass, but there is no method for setting a page name. Do I really need to extend the Paginatorclass just to be able to change the page name?
在Paginator类是有方法的变化基本URL(setBaseUrl()中)Environment类,但有一个设置页面名称的方法。我真的需要扩展Paginator类才能更改页面名称吗?
采纳答案by Jason Lewis
Just like you said you can use the setPageNamemethod:
就像你说的,你可以使用这个setPageName方法:
Paginator::setPageName('sida');
You can place that in app/start/global.php.
你可以把它放在app/start/global.php.
回答by Kevin Jung
Just came across this same issue for 5.1and you can pass the page name like this:
刚刚遇到同样的问题5.1,您可以像这样传递页面名称:
Post::paginate(1, ['*'], 'new-page-name');
回答by razzbee
Well that didnt work for me in laravel 5 , in laravel 5 you will need to do more extra work by overriding the PaginationServiceProvider because the queryName "page" was hardcoded in there , so first create your new PaginationServiceProvider in /app/providers ,This was mine
好吧,这在 laravel 5 中对我不起作用,在 laravel 5 中,您需要通过覆盖 PaginationServiceProvider 来做更多的额外工作,因为 queryName“页面”在那里是硬编码的,所以首先在 /app/providers 中创建新的 PaginationServiceProvider,这是矿
<?php
namespace App\Providers;
use Illuminate\Pagination\Paginator;
use Illuminate\Support\ServiceProvider as ServiceProvider;
class PaginationServiceProvider extends ServiceProvider {
//boot
public function boot()
{
Paginator::currentPageResolver(function()
{
return $this->app['request']->input('p');
});
}//end boot
public function register()
{
//
}
}
Then in your controllers you can do this
然后在您的控制器中,您可以执行此操作
$users = User::where("status","=",1)
->paginate(5)
->setPageName("p");

