laravel 在分页中只显示下一个和上一个链接
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26148645/
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
laravel show only next and previous link in pagination
提问by user3150060
I ma trying to use Laravel Pagination and I only want to show the Previous and Next link with out the number 1 2 3 ...
我试图使用 Laravel 分页,我只想显示不带数字 1 2 3 的上一个和下一个链接......
how could I do that? I followed Laravel page : "Simple Pagination"
我怎么能那样做?我关注了 Laravel 页面:“简单分页”
If you are only showing "Next" and "Previous" links in your pagination view, you have the option of using the simplePaginate method to perform a more efficient query. This is useful for larger datasets when you do not require the display of exact page numbers on your view:
如果您只在分页视图中显示“Next”和“Previous”链接,您可以选择使用 simplePaginate 方法来执行更有效的查询。当您不需要在视图上显示准确的页码时,这对于较大的数据集很有用:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
but this still shows the page number when I do this in my view:
但是当我在我看来这样做时,这仍然显示页码:
<?php echo $someUsers->links(); ?>
can anyone help
谁能帮忙
Thanks
谢谢
回答by Jarek Tkaczyk
tldr; you want to use simplePaginate()
method on the query ANDlinks('some.view')
on the paginator (in the view) in order to achieve what you ask for.
tldr; 您想simplePaginate()
在查询和links('some.view')
分页器(在视图中)上使用方法来实现您的要求。
Here's what you need in order to show chosen links in given template:
以下是在给定模板中显示所选链接所需的内容:
// inline choose simple links (prev, next)
{{ $someUsers->links('pagination::simple') }}
// inline choose slider links
{{ $someUsers->links('pagination::slider') }}
// inline choose slider-3 (default)
{{ $someUsers->links('pagination::slider-3') }}
These are framework's templates, placed in laravels directory: Illuminate/Pagination/views/
这些是框架的模板,放置在 laravel 目录中: Illuminate/Pagination/views/
You can always decide to use your custom templates, for this simply call:
您可以随时决定使用您的自定义模板,为此只需调用:
// assuming you have it in app/views/pagination/my-links.blade.php
{{ $someUsers->links('pagination.my-links') }}
// or using views namespace (you need to define it first)
{{ $someUsers->links('myNamespace::my-links') }}
Of course you can define your links as default in app/config/view.php
:
当然,您可以在app/config/view.php
以下位置将链接定义为默认值:
// instead of
'pagination' => 'pagination::slider-3',
// something like
'pagination' => 'pagination.my-links',
回答by Marcin Nabia?ek
You need to use:
您需要使用:
$someUsers = User::where('votes', '>', 100)->simplePaginate(15);
as you used
正如你所使用的
and in app/config/view.php
you need to set pagination
to pagination::simple
(by default it's set to pagination::slider-3
). Then you'll have by default pagination as in the image:
并且app/config/view.php
您需要设置pagination
为pagination::simple
(默认情况下设置为pagination::slider-3
)。然后,默认情况下,您将拥有如图所示的分页:
You can also set custom text for previous and next items editing file lang/en/pagination.php
(for other language of course you need to change it in other lang directory). By default it's set to:
您还可以为上一个和下一个项目编辑文件设置自定义文本lang/en/pagination.php
(对于其他语言,您当然需要在其他 lang 目录中更改它)。默认情况下,它设置为:
'previous' => '« Previous',
'next' => 'Next »',
but you can change it to:
但您可以将其更改为:
'previous' => '«',
'next' => '»',
and then it will look like as in the image:
然后它看起来像图像中的那样:
回答by Jeff Lambert
See the very bottom of this manual pageto see how to implement a custom view for the pagination. Summarizing, you need to follow these steps:
请参阅本手册页的最底部,了解如何为分页实现自定义视图。总结一下,您需要按照以下步骤操作:
- Create a view for the paginator somewhere in
app/views
. - Replace the
pagination
option inapp/config/views.php
with the path Laravel will use to locate your new view. Display your custom paginatation view in your view like this:
<?php echo with(new ZurbPresenter($paginator))->render(); ?>
- 在
app/views
. - 用Laravel 用于定位新视图的路径替换中的
pagination
选项app/config/views.php
。 在您的视图中显示您的自定义分页视图,如下所示:
<?php echo with(new ZurbPresenter($paginator))->render(); ?>
Where ZurbPresenter
is the class name of your pagination presenter.
ZurbPresenter
分页演示者的类名在哪里。
回答by Thomas Jensen
In config/view.php
:
在config/view.php
:
/*
|--------------------------------------------------------------------------
| Pagination View
|--------------------------------------------------------------------------
|
| This view will be used to render the pagination link output, and can
| be easily customized here to show any view you like. A clean view
| compatible with Twitter's Bootstrap is given to you by default.
|
*/
'pagination' => 'pagination::slider-3',
Set this to simple
.
将此设置为simple
。
Source: http://youtu.be/lIEcyOUcNQk?t=8m00s
来源:http: //youtu.be/lIEcyOUcNQk?t=8m00s