Laravel分页重定向分页、重定向、Laravel

2023-09-02 01:06:34 作者:展眉

我用Laravel 4分页,并希望删除页= 1 和服务的默认字符串,而不是;例如:

I'm using Laravel 4 pagination, and want to remove the page=1 and serve the default string instead; for example:

http://domain.com/search-results/

而不是

Of course, for page >=2, it's just fine to leave:

当然,对于网页> = 2,这只是罚款离开:

http://domain.com/search-results/?page=2


推荐答案

目前Laravel将始终默认为显示?页= 1

Currently Laravel will always default to showing ?page=1.

完成你想要的东西(总是默认为不显示页= 1 ?)包括扩展/使用自己的 presenter 和/或同时使用自定义分页视图

Accomplishing what you want (always defaulting to not showing ?page=1) involves a mix of extending/using your own Presenter and/or also by using a custom Pagination view.

股票分页的观点在这里,但你可以创建自己的 view.php 配置。

Stock pagination views are here, but you can create your own and define it within the view.php config.

在我的博客,我做类似的。我的分页的观点是这里。你可以看到它加载在自定义presenter类。

In my blog, I do similar. My pagination view is here. You can see it loads in a custom Presenter class.

请注意,我的博客可能不是最新的与最新的Laravel code,但应该让你用自己的方式让你需要做的,实现这一目标的编辑。

Note that my blog may not be up to date with latest Laravel code, but that should get you on your way to making the edits you need to do to accomplish that.

您可以可以跳过code完全和使用server配置重定向 - 该链接假定阿帕奇

You may be able to skip code altogether and use a server configuration to redirect - That link assumes Apache.