我使用CI4.我已经成功地实现了分页.我有9个职位,并已使用'3'分页,因此3页.一切都工作得很好,但CSS是可怕的.这里是一个pict的分页.而不是页数是正确的.
的数据
因此,我将bootstrap 4 css添加到CI的分页。当我添加bootstrap 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>
型
2条答案
按热度按时间col17t5w1#
您已指定要使用
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'); ?>
wooyq4lh2#
只是为了帮助其他人和初学者,这里是我的方法:
第一个月
字符串
我创建了一个视图文件
app\Views\Pager\my_pagination.php
(bootstrap 4)型
然后使用,我写的控制器如下:
型
在下面的视图中:
型
我得到的结果如下:
的数据