2013-04-04 1 views
0

Я пытаюсь получить Pagination, работающий в Laravel. Я раньше не использовал разбиение на страницы, поэтому я пытаюсь использовать некоторые примеры из документов и результатов Google. Мне интересно, нужно ли мне превращать «разбивку на страницы» где-то в конфиге.Пытаясь использовать laravel pagination разбивает мой контроллер/вид

Вот мой простой рабочий контроллер:

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 

ответ

0

Я не читал достаточно глубоко в теме. Теперь он работает, и вот что мне пришлось изменить на вид:

//from: 
@foreach($locations as $location) 

//to: 
@foreach($locations->results as $location) 

Это вернуло всего 5 результатов. Затем добавить ссылки на сноску моего стола я добавил этот HTML/Клинок:

<tfoot> 
    <tr> 
    <td colspan="5"> {{ $locations->links() }} </td> 
    </tr> 
</tfoot> 

Надежда кто-то другая выгода, как я не нашел это очень ясно в документации.