现在我有一个工作照相馆,里面有基本的 Crud。 在 View Show 中,在图片下方,我想添加分页:让观看留在 Show View 中的其他图片成为可能,而不是返回到 Index View 。
我尝试阅读文档:http://four.laravel.com/docs/pagination 但是不起作用。
有人可以告诉我我必须做什么吗?
非常感谢!
编辑:
这是显示方法:
public function show($id)
{
$photo = Photo::find($id);
return View::make('photos.show', compact('photo'));
}
这是显示 View :
@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
最佳答案
在你的 Controller 中
public function show(){
$photos = Photo::paginate(10);
return View::make('photos.show', array('photos' => $photos));
}
然后在你看来就这样做
@foreach ($photos as $photo)
{{ $photo->title }}
@endforeach
// executed from passed variable into view
{{ $photos->links() }}
关于php - 拉维尔 4 : How to make pagination,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18375399/