Bootstrap 4分页与CakePHP 2分页助手

时间:2018-01-16 05:03:40

标签: pagination cakephp-2.0 bootstrap-4

在CakePHP 2.x中,我可以使用下面的代码在Bootstrap 3中完美地输出分页:

<ul class="pagination">
    <?php
    echo $this->Paginator->prev(__('Previous'), array('tag' => 'li'), null, array('tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a'));
    echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'currentClass' => 'active', 'tag' => 'li', 'first' => 1, 'last' => 5, 'ellipsis' => '<li class="disabled"><a>...</a></li>'));
    echo $this->Paginator->next(__('Next'), array('tag' => 'li'), null, array('tag' => 'li', 'class' => 'disabled', 'disabledTag' => 'a'));
    ?>
</ul>

输出结果为:

<ul class="pagination">
    <li class="prev">
        <a href="/" rel="prev">Previous</a>
    </li>
    <li>
        <a href="/">1</a>
    </li>
    <li class="active">
        <a>2</a>
    </li>
    <li>
        <a href="/services/index/page:3">3</a>
    </li>
    <li class="next">
        <a href="/services/index/page:3" currentClass="disabled" rel="next">Next</a>
    </li>
</ul>

但现在Bootstrap 4 Beta改变了每个元素内部类的结构,如下所示:

<nav aria-label="...">
    <ul class="pagination">
        <li class="page-item disabled">
            <a class="page-link" href="#">Previous</a>
        </li>
        <li class="page-item"><a class="page-link" href="#">1</a></li>
        <li class="page-item active">
            <a class="page-link" href="#">2</a>
        </li>
        <li class="page-item"><a class="page-link" href="#">3</a></li>
        <li class="page-item">
            <a class="page-link" href="#">Next</a>
        </li>
    </ul>
</nav>

请帮助在CakePHP 2.x中为上述输出设置Paginator的选项。

1 个答案:

答案 0 :(得分:0)

您可以使用以下代码完成

<ul class="pagination">
<?php
    echo $this->Paginator->prev('< ' . __('Previous'), array('tag' => 'li', 'class'=>'page-item', ' class'=>'page-link'), null, array('class' => 'disabled page-item', 'tag' => 'li', 'disabledTag' => 'a', ' class' =>'page-link'));
    echo $this->Paginator->numbers(array('separator' => '', 'currentTag' => 'a', 'tag' => 'li', 'class'=>'page-item',  'currentClass' => 'disabled page-link', ' class'=>'page-link'));
    echo $this->Paginator->next(__('Next') . ' >', array('tag' => 'li', 'class'=>'page-item', ' class'=>'page-link'), null, array('class' => 'disabled page-item', 'tag' => 'li', 'disabledTag' => 'a', 'currentClass'=>'page-link', ' class' =>'page-link'));
?> </ul> 

关键是使用名为“ class”的数组元素,并将引导程序类放在此处