我有一个分页视图,但问题是我有这么多项目,像这样的
我想要的是显示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 :(得分:0)
默认情况下,Laravel将使用&#34;滑动&#34;但是,页面编号需要至少13页才能创建&#34;滑动&#34;页码。如果您的页数少于13页,则默认为普通页面范围。
不幸的是,这个数字被硬编码到Laravel中。
请参阅Presenter
类中负责构建页面的this comment (v4.1.24)。
答案 1 :(得分:0)
您可以使用自己的观点:
配置/ 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
}
?>