Laravel 4 Laravel 4自定义分页:转到第一页/最后一页并显示固定数量的链接
我在Laravel 4中使用默认的引导滑块导航,效果非常好:但现在我想通过两个自定义来改进它,我不知道如何: 1:在开始处添加转到第一页,如果我们在第一页,则禁用;最后还有一个类似的“转到最后一页”,如果我们在最后一页,则禁用。请查看箭头与默认的Laravel内容相比是如何更改的!我想用双箭头«和»表示转到第一个/最后一个,用单箭头è和›表示转到上一个/下一个:Laravel 4 Laravel 4自定义分页:转到第一页/最后一页并显示固定数量的链接,laravel-4,pagination,Laravel 4,Pagination,我在Laravel 4中使用默认的引导滑块导航,效果非常好:但现在我想通过两个自定义来改进它,我不知道如何: 1:在开始处添加转到第一页,如果我们在第一页,则禁用;最后还有一个类似的“转到最后一页”,如果我们在最后一页,则禁用。请查看箭头与默认的Laravel内容相比是如何更改的!我想用双箭头«和»表示转到第一个/最后一个,用单箭头è和›表示转到上一个/下一个: <ul class="pagination"> <li class="disabled"><sp
<ul class="pagination">
<li class="disabled"><span>«</span></li>
<li class="disabled"><span>‹</span></li>
<li class="active"><span>1</span></li>
<li><a href="http://laravel/games?page=2">2</a></li>
<li><a href="http://laravel/games?page=3">3</a></li>
<li><a href="http://laravel/games?page=4">4</a></li>
<li><a href="http://laravel/games?page=5">5</a></li>
<li><a href="http://laravel/games?page=6">6</a></li>
<li><a href="http://laravel/games?page=7">7</a></li>
<li><a href="http://laravel/games?page=8">8</a></li>
<li><a href="http://laravel/games?page=9">9</a></li>
<li><a href="http://laravel/games?page=10">10</a></li>
<li><a href="http://laravel/games?page=2" rel="next">›</a></li>
<li><a href="http://laravel/games?page=10" rel="last">»</a></li>
</ul>
求求你,有什么帮助吗
提前谢谢 给你
<?php
class MyPresenter extends Illuminate\Pagination\BootstrapPresenter {
public function render()
{
if ($this->currentPage == 1) {
$content = $this->getPageRange(1, $this->currentPage + 2);
}
else if ($this->currentPage >= $this->lastPage) {
$content = $this->getPageRange($this->currentPage - 2, $this->lastPage);
}
else {
$content = $this->getPageRange($this->currentPage - 1, $this->currentPage + 1);
}
return $this->getFirst().$this->getPrevious('‹').$content.$this->getNext('›').$this->getLast();
}
public function getFirst($text = '«')
{
if ($this->currentPage <= 1)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl(1);
return $this->getPageLinkWrapper($url, $text);
}
}
public function getLast($text = '»')
{
if ($this->currentPage >= $this->lastPage)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl($this->lastPage);
return $this->getPageLinkWrapper($url, $text);
}
}
}
当然,这并不完美,如果总页数少于3页,您可能会遇到问题,但这将使您走上正确的道路。谢谢Jofry,您为我指明了正确的方向,最后我完成了自己的Laravel软件包::-
<ul class="pagination">
<li><a href="http://laravel/games?page=1" rel="first">«</a></li>
<li><a href="http://laravel/games?page=3" rel="prev">‹</a></li>
<li><a href="http://laravel/games?page=2">2</a></li>
<li><a href="http://laravel/games?page=3">3</a></li>
<li class="active"><span>4</span></li>
<li><a href="http://laravel/games?page=5">5</a></li>
<li><a href="http://laravel/games?page=6">6</a></li>
<li><a href="http://laravel/games?page=4" rel="next">›</a></li>
<li><a href="http://laravel/games?page=10" rel="last">»</a></li>
</ul>
<?php
$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pagination">
</ul>
<?php endif; ?>
<?php
class MyPresenter extends Illuminate\Pagination\BootstrapPresenter {
public function render()
{
if ($this->currentPage == 1) {
$content = $this->getPageRange(1, $this->currentPage + 2);
}
else if ($this->currentPage >= $this->lastPage) {
$content = $this->getPageRange($this->currentPage - 2, $this->lastPage);
}
else {
$content = $this->getPageRange($this->currentPage - 1, $this->currentPage + 1);
}
return $this->getFirst().$this->getPrevious('‹').$content.$this->getNext('›').$this->getLast();
}
public function getFirst($text = '«')
{
if ($this->currentPage <= 1)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl(1);
return $this->getPageLinkWrapper($url, $text);
}
}
public function getLast($text = '»')
{
if ($this->currentPage >= $this->lastPage)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl($this->lastPage);
return $this->getPageLinkWrapper($url, $text);
}
}
}
<ul class="pagination">
<?php echo with(new MyPresenter($paginator))->render(); ?>
</ul>