Laravel 4 分页与 Bootstrap 3
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18983345/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel 4 pagination with Bootstrap 3
提问by FrancescoMussi
I using the pagination into a bootstrap 3 app and there is something wrong. This is how i call the pagination:
我将分页用于引导程序 3 应用程序,但出现问题。这就是我调用分页的方式:
$newsletterUsers = NewsletterUser::paginate(2);
And then after the foreach loop i put this:
然后在 foreach 循环之后我把这个:
{{ $newsletterUsers->links() }}
That's all right? but instead of showing the normal nice laravel pagination, there the numbers one over the other, without style, and are even not paginated correctly since it paginate with 1 - 1 - 2 elements and not 2 - 2 as it should be
没关系?但不是显示正常的漂亮的 Laravel 分页,而是一个在另一个之上的数字,没有样式,甚至没有正确分页,因为它用 1 - 1 - 2 个元素而不是 2 - 2 分页,因为它应该是
And this is the html markup:
这是 html 标记:
<div class="pagination">
<ul>
<li><a href="---/public/newsletterConfirmedUser?page=2">«</a></li>
<li><a href="---/public/newsletterConfirmedUser?page=1">1</a></li>
<li><a href="---/public/newsletterConfirmedUser?page=2">2</a></li>
<li class="active"><span>3</span></li><li class="disabled">
<span>»</span></li>
</ul>
</div>
Someone can help me please?
有人可以帮我吗?
回答by jobnomade
When you look into the laravel 4 core framework's Paginator, you will see in the view folder vendor/laravel/Illuminate/Paginator/viewsa file called slider-3.php! This view uses the bootstrap 3 paginator
当您查看 laravel 4 核心框架的分页器时,您会在视图文件夹vendor/laravel/Illuminate/Paginator/views 中看到一个名为 Slider-3.php 的文件!此视图使用引导程序 3 分页器
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pagination">
<?php echo $presenter->render(); ?>
</ul>
Knowing this, you simply change the paginator in the app/config/view to
知道了这一点,您只需将 app/config/view 中的分页器更改为
'pagination' => 'pagination::slider-3',
And done.
并做了。
回答by jfortunato
Laravel currently only works with bootstrap 2's pagination but you can use a workaround for now until bootstrap 3 is supported.
Laravel 目前仅适用于引导程序 2 的分页,但您现在可以使用一种解决方法,直到支持引导程序 3。
First create a view that will use bootstrap 3's pagination syntax by making a new file at "app/views/pagination.php"
首先通过在“app/views/pagination.php”中创建一个新文件来创建一个将使用 bootstrap 3 的分页语法的视图
app/views/pagination.php
应用程序/视图/pagination.php
<?php
$presenter = new Illuminate\Pagination\BootstrapPresenter($paginator);
?>
<?php if ($paginator->getLastPage() > 1): ?>
<ul class="pagination">
<?php echo $presenter->render(); ?>
</ul>
<?php endif; ?>
Then open up the file app/config/view.php
然后打开文件app/config/view.php
and near the bottom you will see a line that reads
在底部附近你会看到一条线,上面写着
'pagination' => 'pagination::slider',
which you can change to read
您可以更改为阅读
'pagination' => 'pagination',
Now you should be able to use laravels pagination as you normally would.
现在你应该可以像往常一样使用 laravel 分页了。