2012-06-14 26 views
0

我不确定这是否像我想的那么容易,但我希望让paginator在显示1时只有我的表格只有一个页面。如何获得Paginator->数字()来显示1

我想这是可以做到这样的事情:

<p> <?php echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); ?>; 
    <?php if(1 >= $this->Paginator->numbers()) 
       echo 1; 
      else 
       echo $this->Paginator->numbers(); ?> 
    <?php echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?>; </p> 

但后来我意识到,paginator->号()返回的1形式链接| 2 | 3等。

目前分页程序会显示:

<<Previous Next>> 

当只有一个表中的页面,但2个或更多的页面就说明

<<Previous 1|2 Next>> 

我想有它显示一个编号,包括1个单页表。

任何帮助将是伟大的。 感谢

+0

我做你上面显示出什么克服这一点。但是,还没有研究过它,所以可能有另一种方法。 – tigrang

回答

1

你可以做的是创建一个名为pagination.ctp的元素,并把下面的内部:

<p> 
<?php 
    echo $this->Paginator->prev('« Previous', null, null, array('class' => 'disabled')); 
    $numbers = $this->Paginator->numbers(); 
    if (empty($numbers)) { 
     $numbers = 1; // or any markup you need 
    } 
    echo $numbers; 
    echo $this->Paginator->next('Next »', null, null, array('class' => 'disabled')); ?> 
</p> 

然后,每当你需要:

<?php echo $this->element('pagination'); ?> 
+0

真棒,这很好。谢谢 – RXC