2015-01-16 2 views
22

내 laravel4 응용 프로그램을 laravel 5로 포팅하려고합니다. 이전 버전에서는 다음과 같은 방법으로 페이지 매김 URL을 생성 할 수있었습니다. 제어기에서laravel 5에서 페이지 매김을 사용하는 방법은 무엇입니까?

:

$this->data['pages']= Page::whereIn('area_id', $suburbs)->where('score','>','0')->orderBy('score','desc')->paginate(12); 

및 뷰와 데이터 배열을 공유 후,이

보기
에서

사용자 수 :

{{$pages->links()}} 

laravel 5는 고 다음과 같은 오류가 발생합니다.

ErrorException in AbstractPaginator.php line 445: 
call_user_func_array() expects parameter 1 to be a valid callback, class 'Illuminate\Support\Collection' does not have a method 'links' 

여기에 누락 된 내용이 확실하지 않은 경우 누군가 도움이 될 수 있습니까?

+3

버그가 있고 기본 코드가 변경 될 수 있기 때문에 Laravel 5가 안정 될 때까지 기다리는 것이 좋습니다. –

+0

@ClaudioLudovicoPanetta 이번 달에 출시 될 것이라고 생각합니다. :) 변경 사항과 동기화되기를 원했습니다. 생산을 위해 4.2를 사용합니다. –

+1

귀하의 문제가 귀하의 문제보다 더 많은 Laravel 문제로 보입니다. 해결책에 대한 문제를 귀하에게 재현하려고합니다. –

답변

56

는 Laravel 5에서있는 방법 "링크"가없는 당신은 시도 할 수 있습니다이

{!! $pages->render() !!} 
+12

에 문제가 추가됩니다. {!! $ pages-> render() !!} laravel5의 다른 구문은 html을 이스케이프 처리했습니다. 덕분에 –

+0

마지막으로 간단한 페이지 매김에 대한 해결책이 아니라 새로운 "5 개의 PHP 파일 만들기, 클래스 구현 및 200 줄의 코드 작성"이 아닙니다. 마침내! 고맙습니다. – hfingler

+0

이 작동하지 않습니다. 그것을 사용하기 전에 먼저 준비해야 할 것이 있습니까? – Muhaimin

-5

안녕하세요 매김 내 코드가있다 :보기 사용 :
@include ('pagination.default'[ '매기기'=> $ 사용자])

조회수/매김 다른 프레임 워크에서/default.blade.php

@if ($paginator->lastPage() > 1) 
    <ul class="pagination"> 
     <!-- si la pagina actual es distinto a 1 y hay mas de 5 hojas muestro el boton de 1era hoja --> 
     <!-- if actual page is not equals 1, and there is more than 5 pages then I show first page button --> 
     @if ($paginator->currentPage() != 1 && $paginator->lastPage() >= 5) 
      <li> 
       <a href="{{ $paginator->url($paginator->url(1)) }}" > 
        << 
       </a> 
      </li> 
     @endif 

     <!-- si la pagina actual es distinto a 1 muestra el boton de atras --> 
     @if($paginator->currentPage() != 1) 
      <li> 
       <a href="{{ $paginator->url($paginator->currentPage()-1) }}" > 
        < 
       </a> 
      </li> 
     @endif 

     <!-- dibuja las hojas... Tomando un rango de 5 hojas, siempre que puede muestra 2 hojas hacia atras y 2 hacia adelante --> 
     <!-- I draw the pages... I show 2 pages back and 2 pages forward --> 
     @for($i = max($paginator->currentPage()-2, 1); $i <= min(max($paginator->currentPage()-2, 1)+4,$paginator->lastPage()); $i++) 
       <li class="{{ ($paginator->currentPage() == $i) ? ' active' : '' }}"> 
        <a href="{{ $paginator->url($i) }}">{{ $i }}</a> 
       </li> 
     @endfor 

     <!-- si la pagina actual es distinto a la ultima muestra el boton de adelante --> 
     <!-- if actual page is not equal last page then I show the forward button--> 
     @if ($paginator->currentPage() != $paginator->lastPage()) 
      <li> 
       <a href="{{ $paginator->url($paginator->currentPage()+1) }}" > 
        > 
       </a> 
      </li> 
     @endif 

     <!-- si la pagina actual es distinto a la ultima y hay mas de 5 hojas muestra el boton de ultima hoja --> 
     <!-- if actual page is not equal last page, and there is more than 5 pages then I show last page button --> 
     @if ($paginator->currentPage() != $paginator->lastPage() && $paginator->lastPage() >= 5) 
      <li> 
       <a href="{{ $paginator->url($paginator->lastPage()) }}" > 
        >> 
       </a> 
      </li> 
     @endif 
    </ul> 
@endif 
+0

나는 잘 복사하지 못했다. 코드는 회색 영역보다 먼저 시작한다. – diego

+1

코드를 언제든지 편집 할 수 있습니다 (http://stackoverflow.com/posts/30744604/edit)! – ZygD

4

를 매김은 V 할 수 있습니다 에리 고통 스럽다. Laravel 5는 그것을 산들 바람처럼 만듭니다.

<?php echo $users->render(); ?> 

것입니다 :이 코드를 사용할 수 있습니다 그 후 ...

public function index() 
{  
     $users = DB::table('books')->simplePaginate(5); 
     //using pagination method 
     return view('index', ['users' => $users]); 
} 

: 그것을 사용하기 위해, 먼저 당신이 데이터베이스에서 데이터를 호출하는 컨트롤러 코드의 변경을해야 간단한 Laravel 5 뷰티를 사용하게하십시오.

-1
@if ($posts->lastPage() > 1) 
     <nav aria-label="Page navigation"> 
      <ul class="pagination"> 
       @if($posts->currentPage() != 1 && $posts->lastPage() >= 5) 
       <li> 
        <a href="{{ $posts->url($posts->url(1)) }}" aria-label="Previous"> 
         <span aria-hidden="true">First</span> 
        </a> 
       </li> 
       @endif 
       @if($posts->currentPage() != 1) 
       <li> 
        <a href="{{ $posts->url($posts->currentPage()-1) }}" aria-label="Previous"> 
         <span aria-hidden="true">&#x3C;</span> 
        </a> 
       </li> 
       @endif 
       @for($i = max($posts->currentPage()-2, 1); $i <= min(max($posts->currentPage()-2, 1)+4,$posts->lastPage()); $i++) 
       @if($posts->currentPage() == $i) 
       <li class="active"> 
       @else 
       <li> 
       @endif 
        <a href="{{ $posts->url($i) }}">{{ $i }}</a> 
       </li> 
       @endfor 
       @if ($posts->currentPage() != $posts->lastPage()) 
       <li> 
        <a href="{{ $posts->url($posts->currentPage()+1) }}" aria-label="Next"> 
         <span aria-hidden="true">&#x3E;</span> 
        </a> 
       </li> 
       @endif 
       @if ($posts->currentPage() != $posts->lastPage() && $posts->lastPage() >= 5) 
       <li> 
        <a href="{{ $posts->url($posts->lastPage()) }}" aria-label="Next"> 
         <span aria-hidden="true">Last</span> 
        </a> 
       </li> 
       @endif 
      </ul> 
     </nav> 
     @endif 
+0

몇 가지 설명을 해주십시오. 대답은 적어도 조금 설명해야합니다. –