Laravel pagination redirect

让人想犯罪 __ 提交于 2019-12-24 12:35:01

问题


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/

instead of

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

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

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

回答1:


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

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.

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

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

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.

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



来源:https://stackoverflow.com/questions/21305857/laravel-pagination-redirect

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!