2

如何获取Cake php默认分页以获取第一页和最后一页分页链接

<p>
    <?php
    echo $this->Paginator->counter(array(
        'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
    ));
    ?>    </p>

<div class="paging">
    <?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class' => 'disabled'));?>
    |     <?php echo $this->Paginator->numbers();?>
    |
    <?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>

这将输出

Page 1 of 89, showing 15 records out of 1326 total, starting on record 1, ending on 15

<< previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | next >> 

我如何使用默认分页获得首页和最后一页链接

first | << previous | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | next >> | last
4

3 回答 3

16

我尝试了这段代码,它在 cakephp 1.3 中为我工作:--

<?php echo $this->Paginator->first(__('<< First', true), array('class' => 'number-first'));?>
<?php echo $this->Paginator->numbers(array('class' => 'numbers', 'first' => false, 'last' => false));?>
<?php echo $this->Paginator->last(__('>> Last', true), array('class' => 'number-end'));?>

尝试实现这个...

这就是你要找的:--

        <?php echo $this->Paginator->first(__('First', true), array('class' => 'disabled'));?>
|     <?php echo $this->Paginator->prev('<< ' . __('Previous', true), array(), null, array('class'=>'disabled'));?>
|     <?php echo $this->Paginator->numbers(array('class' => 'numbers', 'first' => false, 'last' => false));?>
|     <?php echo $this->Paginator->next(__('Next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
|     <?php echo $this->Paginator->last(__('Last', true), array('class' => 'disabled'));?>

在此处输入图像描述

于 2012-05-21T12:05:54.880 回答
1

我不确定我是否正确理解了您的问题,但只需打开帮助页面:

PaginatorHelper::first()

PaginatorHelper::last()

于 2012-05-21T11:56:30.430 回答
0

对于 cakephp-3.x

您一直希望首页链接会显示出来,当您到达第 5 页或更高时,您可以使用:

<?php if ($this->Paginator->counter('{{page}}') >= 5): ?>
    <li class="">
    <?php echo $this->Paginator->first('First'); ?>
    </li>
<?php endif; ?>

同样对于最后一页,如果您只有 5 页或更少的页面,则不需要最后一页链接。在这种情况下,您可以使用:

<?php if ($this->Paginator->counter('{{pages}}') > 5): ?>
    <li class="paginate_button last">
    <?php echo $this->Paginator->last('Last') ?>
    </li>
<?php endif; ?>
于 2018-01-12T06:28:53.510 回答