栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Laravel分页漂亮的URL

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Laravel分页漂亮的URL

这是一个骇人的解决方法。我正在使用Laravel
v4.1.23。假设页码是您网址的最后一位。还没有进行深入的测试,因此我对人们可以找到的任何bug感兴趣。我对更好的解决方案更感兴趣:-)

路线:

Route::get('/articles/page/{page_number?}', function($page_number=1){    $per_page = 1;    Articles::resolveConnection()->getPaginator()->setCurrentPage($page_number);    $articles = Articles::orderBy('created_at', 'desc')->paginate($per_page);    return View::make('pages/articles')->with('articles', $articles);});

视图:

<?php    $links = $articles->links();    $patterns = array();    $patterns[] = '/'.$articles->getCurrentPage().'?page=/';    $replacements = array();    $replacements[] = '';    echo preg_replace($patterns, $replacements, $links);?>

模型:

<?phpclass Articles extends Eloquent {    protected $table = 'articles';}

移民:

<?phpuse IlluminateDatabaseSchemaBlueprint;use IlluminateDatabaseMigrationsMigration;class CreateArticlesTable extends Migration {    public function up()    {        Schema::create('articles', function($table){ $table->increments('id'); $table->string('slug'); $table->string('title'); $table->text('body'); $table->timestamps();        });    }    public function down()    {        Schema::drop('articles');    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/421727.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号