Pagination 尝试使用laravel分页会中断我的控制器/视图
我正试图让分页在拉威尔工作。我以前没有使用过分页,所以我尝试使用文档和谷歌结果中的一些示例。我想知道是否需要在配置中的某个地方打开“分页” 这是我的简单工作控制器:Pagination 尝试使用laravel分页会中断我的控制器/视图,pagination,laravel,eloquent,laravel-3,Pagination,Laravel,Eloquent,Laravel 3,我正试图让分页在拉威尔工作。我以前没有使用过分页,所以我尝试使用文档和谷歌结果中的一些示例。我想知道是否需要在配置中的某个地方打开“分页” 这是我的简单工作控制器: public function get_index() { $locations = Location::all(); return View::make('location.index')->with('locations', $locations)->render(); } 当我尝试像这样添加分页时,它会中
public function get_index() {
$locations = Location::all();
return View::make('location.index')->with('locations', $locations)->render();
}
当我尝试像这样添加分页时,它会中断:
public function get_index() {
$locations = Location::paginate(5);
return View::make('location.index')->with('locations', $locations)->render();
}
…我得到一个错误:
Unhandled Exception
Message:
Error rendering view: [location.index]
Trying to get property of non-object
这是我的location.index视图:
@layout('layouts.blank')
@section('content')
<div class="row">
<div class="twelve columns">
<div role="main" id="content">
<h3>Locations - All</h3>
@if($locations)
<table class="twelve">
<thead>
<tr>
<th style="text-align: left;">Address</th>
<th>Area</th>
<th>Region</th>
<th>Edit</th>
<th>Delete</th>
</tr>
</thead>
@foreach($locations as $location)
<tbody>
<tr>
<td style="text-align: left;">{{ $location->company,', ',$location->add_name,', ',$location->add_city }}</td>
<td> – </td>
<td> – </td>
<td>{{ HTML::link('location/update/'.$location->id, '',array('class'=>"foundicon-edit updateicon")) }}</td>
<td>{{ HTML::link('location/delete/'.$location->id, '',array('class'=>"foundicon-remove warnicon")) }}</td>
</tr>
</tbody>
@endforeach
</table>
@else
Looks like we haven't added any locations, yet!
@endif
<p>{{ HTML::link('location/create', 'Create a location', array('class'=>"small radius button")) }}</p>
</div>
</div>
</div>
@endsection
@layout('layouts.blank'))
@节(“内容”)
地点-全部
@如果有($地点)
地址
地区
区域
编辑
删除
@foreach($locations作为$location)
{{$location->company',',$location->add_name',',,$location->add_city}
–
–
{HTML::link('location/update/'.$location->id',array('class'=>“foundicon edit updateicon”))}
{HTML::link('location/delete/'.$location->id',array('class'=>“foundicon-remove-warnicon”))}
@endforeach
@否则
看起来我们还没有添加任何位置!
@恩迪夫
{{HTML::link('location/create','create a location',array('class'=>“small radius button”))}
@端部
我对这个主题读得不够深入。它现在正在运行,以下是我在视图中必须更改的内容:
//from:
@foreach($locations as $location)
//to:
@foreach($locations->results as $location)
结果只有5个。然后,为了向我的表的页脚添加链接,我添加了以下HTML/Blade:
<tfoot>
<tr>
<td colspan="5"> {{ $locations->links() }} </td>
</tr>
</tfoot>
{{$locations->links()}
希望其他人能从中受益,因为我在文档中没有发现这一点