gpt4 book ai didi

laravel-4 - Laravel 4 自定义分页 : go to first/last page and show a fixed number of links

转载 作者:行者123 更新时间:2023-12-05 02:23:02 27 4
gpt4 key购买 nike

我在 Laravel 4 中使用默认的 Bootstrap slider 导航并且它工作得非常好:但现在我想通过两个自定义来改进它,但我不知道如何:

1: 在开头添加“转到第一页”,如果我们在第一页则禁用;和最后一个类似的“转到最后一页”,如果我们在最后一页则禁用(请查看箭头与默认的 Laravel 东西相比如何改变!我想使用“双箭头”(« 和 »)用于“转到第一个/最后一个”,单个箭头(‹ 和 ›)用于“转到上一个/下一个:

<ul class="pagination">
<li class="disabled"><span>&laquo;</span></li>
<li class="disabled"><span>&lsaquo;</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">&rsaquo;</a></li>
<li><a href="http://laravel/games?page=10" rel="last">&raquo;</a></li>
</ul>

2:一次显示自定义数量的链接(即 5 个)而不是默认的长列表:

<ul class="pagination">
<li class="disabled"><span>&laquo;</span></li>
<li class="disabled"><span>&lsaquo;</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=2" rel="next">&rsaquo;</a></li>
<li><a href="http://laravel/games?page=10" rel="last">&raquo;</a></li>
</ul>

<ul class="pagination">
<li><a href="http://laravel/games?page=1" rel="first">&laquo;</a></li>
<li><a href="http://laravel/games?page=3" rel="prev">&lsaquo;</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">&rsaquo;</a></li>
<li><a href="http://laravel/games?page=10" rel="last">&raquo;</a></li>
</ul>

想看图片吗?这就是它应该如何用于各种页面(它是一个基于 Bootstrap 2.3.2 构建的旧程序 PHP...我有原始代码但不知道如何“翻译”成 Laravel OOP)

http://www.iwstudio.it/01.png

到目前为止,我创建了一个 custom.php View 并将 laravel/app/config/view.php 中的行 'pagination' => 'pagination::slider-3' 更改为 '分页' => '分页::自定义'

然后,在 custom.php View 中,我卡在了:

<?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('&lsaquo;').$content.$this->getNext('&rsaquo;').$this->getLast();
}

public function getFirst($text = '&laquo;')
{
if ($this->currentPage <= 1)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl(1);
return $this->getPageLinkWrapper($url, $text);
}
}

public function getLast($text = '&raquo;')
{
if ($this->currentPage >= $this->lastPage)
{
return $this->getDisabledTextWrapper($text);
}
else
{
$url = $this->paginator->getUrl($this->lastPage);

return $this->getPageLinkWrapper($url, $text);
}
}
}

随意更改 MyPresenter 类名,并在您的自定义 View 中:

<ul class="pagination">
<?php echo with(new MyPresenter($paginator))->render(); ?>
</ul>

当然这不是很完美(如果总页数少于 3,您可能会遇到问题),但这会让您走上正轨。

关于laravel-4 - Laravel 4 自定义分页 : go to first/last page and show a fixed number of links,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25567741/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com