2014-03-29 100 views
0

我有一個分頁考慮,但問題是我有芒大分頁這樣enter image description here如何在laravel中自定義分頁?

這麼多項目我想是顯示1 2 3 ... 6 7例如我試圖做到這一點,但我沒有發現任何東西,

這是我的行動:

public function index() 
{ 
    // get all the logs 
    $logs = DB::table('services') 
     ->join('logs', 'services.id', '=', 'logs.service_id') 
     ->paginate(20); 
    // load the view and pass the logs 
    return View::make('logs.index',array('logs'=> $logs,'title'=>'Service Logs')); 
} 

這是我的看法:

<div class="container"> 
    @foreach($logs as $key => $value) 
     <tr> 
      <td>{{ $value->domain }}</td> 
      <td>{{ $value->service_port }}</td> 
      <td>{{ $value->checktime }}</td> 
      <td class="text-center"> 
       @if($value->status == 'up') <img src="../img/up3.png" /> 
       @elseif($value->status == 'down') <img src="../img/down3.png" /> 
       @else <img width="30" height="30" src="../img/warning_icon.png" /> 
       @endif 
      </td> 
      <td>{{ $value->response_time }}</td> 
     </tr> 
    @endforeach 
    </div> 
{{$logs->links();}} 

所以我想盡一切辦法做到這一點,所以請,如果有人有任何想法,我將非常感激

回答

0

默認情況下,Laravel將採用「滑動體」頁碼,但是,它需要至少13頁的時候,才創建「滑動」頁碼。如果你的頁面少於13頁,它將默認爲一個普通的頁面範圍。

不幸的是,這個數字是硬編碼到Laravel。

請參閱Presenter中的this comment (v4.1.24)負責構建頁面的類。

+0

是的,它適用於超過13這麼不夠對我來說,謝謝賈森我非常感謝你2回答:) – user3438415

0

你可以用你自己的看法:

的config/view.php

'pagination' => 'my-pagination', 

視圖/我-pagination.php

<?php 
$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator); 
$interval = 3; 
$numberPages = $paginator->getLastPage(); 
$currentPage = $paginator->getCurrentPage(); 

if ($numberPages > 1) 
{ 

    ?> 
    <ul class="pagination pagination-sm"> 
     <?php 
     if ($numberPages <= $interval) 
     { 
      for ($i = 1; $i <= $numberPages; $i++) 
      { 

       ?> 
       <li class="<?php echo $i == $currentPage ? ' active' : ''; ?>"> 
        <a href="<?php echo $paginator->getUrl($i); ?>" ><?php echo $i; ?></a> 
       </li> 
       <?php 
      } 
     } 
     else 
     { 
      if ($currentPage < $interval) 
      { 
       if ($currentPage > 1) 
       { 

        ?> 
        <li class="prev"> 
         <a href="{{ $paginator->getUrl($paginator->getCurrentPage()-1) }}"> 
          <i class="fa fa-angle-double-left"></i> 
         </a> 
        </li> 
        <?php 
       } 
       for ($i = 1; $i <= $interval; $i++) 
       { 

        ?> 
        <li class="<?php echo $i == $currentPage ? ' active' : ''; ?>"> 
         <a href="<?php echo $paginator->getUrl($i); ?>" ><?php echo $i; ?></a> 
        </li> 
        <?php 
       } 
      } 
      elseif ($currentPage > ($numberPages - ($interval - 1))) 
      { 

       ?> 
       <li class="prev"> 
        <a href="{{ $paginator->getUrl($paginator->getCurrentPage()-1) }}"> 
         <i class="fa fa-angle-double-left"></i> 
        </a> 
       </li> 
       <?php 
       for ($i = ($numberPages - ($interval - 1)); $i <= $numberPages; $i++) 
       { 

        ?> 
        <li class="<?php echo $i == $currentPage ? ' active' : ''; ?>"> 
         <a href="<?php echo $paginator->getUrl($i); ?>" ><?php echo $i; ?></a> 
        </li> 
        <?php 
       } 
      } 
      else 
      { 

       ?> 
       <li class="prev"> 
        <a href="{{ $paginator->getUrl($paginator->getCurrentPage()-1) }}"> 
         <i class="fa fa-angle-double-left"></i> 
        </a> 
       </li> 
       <?php 
       for ($i = ($currentPage - 1); $i <= ($currentPage + 1); $i++) 
       { 

        ?> 
        <li class="<?php echo $i == $currentPage ? ' active' : ''; ?>"> 
         <a href="<?php echo $paginator->getUrl($i); ?>" ><?php echo $i; ?></a> 
        </li> 
        <?php 
       } 
      } 
     } 
     if ($paginator->getLastPage() > $paginator->getCurrentPage()) 
     { 

      ?> 
      <li class = "next"><a href = "{{ $paginator->getUrl($paginator->getCurrentPage()+1) }}" class = "{{ ($paginator->getCurrentPage() == $paginator->getLastPage()) ? ' disabled' : '' }}"> 
        <i class = "fa fa-angle-double-right"></i> 
       </a></li> 
      <?php 
     } 

     ?> 
    </ul> 
    <?php 
} 

?>