这是一个骇人的解决方法。我正在使用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'); }}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)