Codeigniter 4 分页正在工作,但是,我的 bootstrap 4 分页模板不起作用
Codeigniter 4 Pagination is working, however, my bootstrap 4 template for pagination is not
我正在使用 CI4。我已经成功实现了分页。我有 9 个帖子,并使用“3”进行分页,因此有 3 页。一切正常,但 css 很糟糕。这是分页的图片。不是正确的页数。
因此,我要将 boostrap 4 css 添加到 CI 的分页中。当我添加 boostrap 4 的分页时,它只显示 1 页。 css 是 bs4 格式,但页面只显示“1”。这是一张照片:
这是我的控制器:
class Post extends BaseController
{
function __construct(){
$this->PostModel = new \App\Models\PostModel;
$this->CategoryModel = new \App\Models\CategoryModel;
}
function index(){
$post_category_id = null;
$category_is_published = 1;
$post_is_published = 1;
$pagination = 1; // this is just to tell the model to return $this instead of the results.
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id,
$category_is_published, $post_is_published, $pagination )->paginate(3);
$this->data['pager'] = $this->PostModel->pager;
return view('Post/post_index', $this->data);
}
}//end controller
这是我的视图文件(当然,我已经缩短了它)。 $pager->links()
会显示正确的页数,但是当我添加 bootstrap 4 模板时,如下所示,它只显示一页。
<?php foreach ($posts as $post) : ?>
<p class="card-text"> <?php echo word_limiter($post->post_body, 30); ?></p>
<?php endforeach; ?>
<?= $pager->links('bootstrap', 'bootstrap4_pagination'); ?>
这是我的 bootstrap4_pagination 模板;
<?php $pager->setSurroundCount(4); ?>
<nav>
<ul class="pagination">
<?php if ($pager->hasPrevious()) { ?>
<li class="page-item">
<a href="<?= $pager->getFirst() ?>" aria-label="First" class="page-link">
<span aria-hidden="true">First</span>
</a>
</li>
<li class="page-item">
<a href="<?= $pager->getPrevious() ?>" class="page-link" aria-label="Previous">
<span>«</span>
</a>
</li>
<?php } ?>
<?php
foreach ($pager->links() as $link) {
$activeclass = $link['active']?'active':'';
?>
<li class="page-item <?= $activeclass ?>">
<a href="<?= $link['uri'] ?>" class="page-link">
<?= $link['title'] ?>
</a>
</li>
<?php } ?>
<?php if ($pager->hasNext()) { ?>
<li class="page-item">
<a href="<?= $pager->getNext() ?>" aria-label="Next" class="page-link">
<span aria-hidden="true">»</span>
</a>
</li>
<li class="page-item">
<a href="<?= $pager->getLast() ?>" aria-label="Last" class="page-link">
<span aria-hidden="true">Last</span>
</a>
</li>
<?php } ?>
</ul>
</nav>
您已指定要使用 bootstrap
群组:
<?= $pager->links('bootstrap', 'bootstrap4_pagination'); ?>
但您没有创建 bootstrap
群组:
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id, $category_is_published, $post_is_published, $pagination )->paginate(3);
这应该是:
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id, $category_is_published, $post_is_published, $pagination )->paginate(3, 'bootstrap');
或者您可以省略组并将 bootstrap
替换为 default
:
<?= $pager->links('default', 'bootstrap4_pagination'); ?>
我正在使用 CI4。我已经成功实现了分页。我有 9 个帖子,并使用“3”进行分页,因此有 3 页。一切正常,但 css 很糟糕。这是分页的图片。不是正确的页数。
因此,我要将 boostrap 4 css 添加到 CI 的分页中。当我添加 boostrap 4 的分页时,它只显示 1 页。 css 是 bs4 格式,但页面只显示“1”。这是一张照片:
这是我的控制器:
class Post extends BaseController
{
function __construct(){
$this->PostModel = new \App\Models\PostModel;
$this->CategoryModel = new \App\Models\CategoryModel;
}
function index(){
$post_category_id = null;
$category_is_published = 1;
$post_is_published = 1;
$pagination = 1; // this is just to tell the model to return $this instead of the results.
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id,
$category_is_published, $post_is_published, $pagination )->paginate(3);
$this->data['pager'] = $this->PostModel->pager;
return view('Post/post_index', $this->data);
}
}//end controller
这是我的视图文件(当然,我已经缩短了它)。 $pager->links()
会显示正确的页数,但是当我添加 bootstrap 4 模板时,如下所示,它只显示一页。
<?php foreach ($posts as $post) : ?>
<p class="card-text"> <?php echo word_limiter($post->post_body, 30); ?></p>
<?php endforeach; ?>
<?= $pager->links('bootstrap', 'bootstrap4_pagination'); ?>
这是我的 bootstrap4_pagination 模板;
<?php $pager->setSurroundCount(4); ?>
<nav>
<ul class="pagination">
<?php if ($pager->hasPrevious()) { ?>
<li class="page-item">
<a href="<?= $pager->getFirst() ?>" aria-label="First" class="page-link">
<span aria-hidden="true">First</span>
</a>
</li>
<li class="page-item">
<a href="<?= $pager->getPrevious() ?>" class="page-link" aria-label="Previous">
<span>«</span>
</a>
</li>
<?php } ?>
<?php
foreach ($pager->links() as $link) {
$activeclass = $link['active']?'active':'';
?>
<li class="page-item <?= $activeclass ?>">
<a href="<?= $link['uri'] ?>" class="page-link">
<?= $link['title'] ?>
</a>
</li>
<?php } ?>
<?php if ($pager->hasNext()) { ?>
<li class="page-item">
<a href="<?= $pager->getNext() ?>" aria-label="Next" class="page-link">
<span aria-hidden="true">»</span>
</a>
</li>
<li class="page-item">
<a href="<?= $pager->getLast() ?>" aria-label="Last" class="page-link">
<span aria-hidden="true">Last</span>
</a>
</li>
<?php } ?>
</ul>
</nav>
您已指定要使用 bootstrap
群组:
<?= $pager->links('bootstrap', 'bootstrap4_pagination'); ?>
但您没有创建 bootstrap
群组:
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id, $category_is_published, $post_is_published, $pagination )->paginate(3);
这应该是:
$this->data['posts'] = $this->PostModel->getPostsByCategory($post_category_id, $category_is_published, $post_is_published, $pagination )->paginate(3, 'bootstrap');
或者您可以省略组并将 bootstrap
替换为 default
:
<?= $pager->links('default', 'bootstrap4_pagination'); ?>