Question

I'm not sure if this is as easy as I think, but I want to get the paginator to display 1 when there is only a single page for my table.

I was thinking it was possible to do something like this:

<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>

But then I realized that paginator->numbers() returns links in the form of 1|2|3 and so on.

Currently the paginator will display:

<<Previous Next>>

when there is only one page in the table but for 2 or more pages it shows

<<Previous 1|2 Next>>

I would like to have it to show a number at all times, including 1 for a single page table.

Any help would be great. Thanks

Was it helpful?

Solution

What you can do is create an element called pagination.ctp and put the following inside:

<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>

Then whenever you need to:

<?php echo $this->element('pagination'); ?>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top