Laravel Pagination与漂亮的URL比查询字符串 [英] Laravel Pagination with pretty urls than query string

查看:143
本文介绍了Laravel Pagination与漂亮的URL比查询字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在freenode中被称为 Kindari @ irc room #laravel的用户,还可归功于用户 iampseudo Debolaz

with credit to the user called Kindari @ irc room #laravel in freenode , also credit goes to user iampseudo and Debolaz.

以下laravel路径代码,

with following laravel route code,

Route::bind('key_pairs', function($s) {
// some logic to transform string to associative array
$arr = explode("/",$s);
$arr2 = array();
if(count($arr)%2 == 0)
{
    for($i=0;$i<count($arr);$i+=2)
    {
        $arr2[$arr[$i]] = $arr[$i+1];
    }
}
return $arr2;   
});

Route::get('foo/{key_pairs}', function($key_pairs) {
var_dump($key_pairs);
})->where('key_pairs', '.*'); 

现在我们可以将/ foo / page / 1用于Laravel读取为/ foo?page = 1 ,但前者比后者更漂亮。

now we can get /foo/page/1 for Laravel to read as /foo?page=1 , but former is more prettier than latter.

现在需要的是Laravel的分页实例读取/ page / 1而不是?page = 1,所以漂亮的分页网址将顺利运行。

now what is needed here is for Laravel's pagination instance to read /page/1 rather than ?page=1 , so pretty pagination urls will work smoothly.

现在有人知道这样做,而不改变基本代码吗?

Does anyone know now to do this , without altering the base code ?

如果我们能有这样的话Users :: paginate(5) - > page($ page)或任何其他功能(如果已经存在)(我无法找到),这很棒。

if we can have something like Users::paginate(5)->page($page) or any other functionality if already exists (which i am unable to find) , that is great.

欢呼

推荐答案

好的问题解决了,现在Laravel的分页网址正在运行,这就是解决方案。

Okay problem solved , now pretty pagination urls for Laravel is working and here is the solution.

我将getByPage方法添加到以下链接中发布的相关模型类中 http://culttt.com/2014/02/24/working-pagination-laravel-4/ (信用证给他)

i added the getByPage method into the relevant model class posted in the following link http://culttt.com/2014/02/24/working-pagination-laravel-4/ (Credit goes to him)

并在路线中调用 $ this-> user-> getByPage($ page,$ limit);

我们有漂亮的分页网址!

There we have Pretty pagination urls !

这篇关于Laravel Pagination与漂亮的URL比查询字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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