Laravel 4:如何进行分页
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18375399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4: How to make pagination
提问by FrancescoMussi
Right now i have a working photo-gallery with basic Crud. In the view Show, under the picture, i would like to add the pagination: giving the possibility to watch other pictures remaining in the Show view, instead of coming back to the Index view.
现在我有一个带有基本 Crud 的工作照片库。在视图显示中,在图片下方,我想添加分页:提供观看显示视图中剩余的其他图片的可能性,而不是返回索引视图。
I try to read the documentation: http://four.laravel.com/docs/paginationBut is not working.
我尝试阅读文档:http: //four.laravel.com/docs/pagination但不起作用。
Can someone please tell me what exactly i have to do?
有人可以告诉我我到底需要做什么吗?
Thank you very much!
非常感谢!
EDIT:
编辑:
This is the Show method:
这是 Show 方法:
public function show($id)
{
$photo = Photo::find($id);
return View::make('photos.show', compact('photo'));
}
And this is the Show view:
这是 Show 视图:
@extends('master')
@section('blog')
<div class="span12 well">
<div class="span12">
<h4> {{ $photo->title }} </h4>
<p>{{ $photo->caption }} </p>
</div>
</div>
<div class="span12 well">
<figure>
<img src="../{{ $photo->path }}" alt="{{ $photo->caption }}">
<br><br>
<div class="span2">
{{ link_to_route('photos.index', '« Back to Index') }}
</div>
</figure>
</div>
@stop
回答by Mohammad Shoriful Islam Ronju
In your controller
在您的控制器中
public function show(){
$photos = Photo::paginate(10);
return View::make('photos.show', array('photos' => $photos));
}
and then in your view just do this
然后在你看来就这样做
@foreach ($photos as $photo)
{{ $photo->title }}
@endforeach
// executed from passed variable into view
{{ $photos->links() }}
回答by Darick
Assuming you have your model setup already
假设你已经有你的模型设置
In your controller a sample RESTful controller:
在您的控制器中,一个示例 RESTful 控制器:
class PhotosController extends BaseController {
public function getPhotos() {
$data['photos'] = Photos::paginate(10);
return View::make('hello')->with($data);
}
}
** You can always change the value, depends on how many you want to display.
** 您可以随时更改该值,具体取决于您要显示的数量。
And in your view:
在您看来:
<html>
<head>
<title>Hello World</title>
</head>
<body>
<!--YOUR TABLE OR PHOTO's HERE-->
{{ $photos->links(); }}
</body>
</html>