Pagination always shows 20 images

Asked

Viewed 433 times

3

I’m doing a gallery using Cakephp’s Pagination. The problem is that I only want to show 15 images per page, but regardless of the value I put in public $paginate, in the limit, 20 images are always shown. With the line $this->Paginator->settings =$this->paginate; uncommented this works, but makes the routes containing the page numbers not work properly. Debugkit also shows that the array Soptions is empty. Why does this happen? Is there any way to make this work with this commented line? I’m using Cake 2.4.4.

Controller

public $components = array('Paginator');
public $paginate = array('maxLimit' => 15, 'order' => array('modified' => 'desc'), 'contain' => array('GalleryImage', 'GalleryVideo'));

public function displayImages(){
        $this->set('title_for_layout', 'Galeria de Fotografias');
        $this->layout = 'default';
        $this->loadModel('GalleryImage');

        //$this->Paginator->settings =$this->paginate;
        $gallery_images=$this->Paginator->paginate('GalleryImage');


        //$gallery_images = $this->GalleryImage->find('all');
        $this->set('gallery_images', $gallery_images);

    //$image_display = $gallery_image['path']
        debug($paginate);
  }

View

<style>
h3{

  text-align: left;
}
</style>
<h3>Galeria</h3>
<br>
 <table width="90%">
<tr>
    <?php
        $i=0;
        foreach( $gallery_images as $gallery_image ):?>
    <td align="center" class="thumbnail" style="display:inline-block;">
    <?php
        $src =$this->webroot. 'img/Gallery/' .$gallery_image['GalleryImage']['name'];
        echo "<a href=\"".$src. "\" rel=\"lightbox\">".$this->Timthumb->image('/img/Gallery/' . $gallery_image['GalleryImage']['name'] , array('width' => 267, 'height' => 189))."  </a>";
    ?>
    </td>
    <?php $i++;
        if($i==3){
            echo "</tr><tr>";
            $i=0;   
        }
    ?>
<?php endforeach ?>
</tr>

</table>
<div class="pagesDiv">
<ul class="pagination">
  <li><?php echo $this->Paginator->first(__('Primeira', true), array());?></li>
  <li><?php echo $this->Paginator->numbers(array('separator' => ''  ,'currentTag' =>'span' ,'class' => 'numbers', 'first' => false, 'last' => false));?></li>
  <li><?php echo $this->Paginator->last(__('Última', true), array('class' => 'disabled'));?></li>
</ul>
</div>
  • Have you tried using only limit instead of maxLimit?

  • @Joaopaulo It was what I was using before maxLimit, and it also doesn’t work.

  • @Joaopaulo I edited my question.

1 answer

2


Try this:

public $paginate = array(
    'maxLimit' => 10,  //Registros por página
    'limit' => 100  //Registros por consulta
    'paramType' => 'querystring' //Esta linha analisa o parâmetro fornecido pelo link.
);
$this->Paginator->settings = $this->paginate;
$resultado = $this->Paginator->paginate('Model');

The above code would result in 10 pages, with 100 results in total.

Or So:

$this->Paginator->settings = array(
        'SeuModel' => array(
                'limit' => 20,
                'maxLimit' => 100,
                'order' => array('SeuModel.campo' => 'ASC') // Por exemplo
        ),
        'OutroModel' => array( ... )
);
  • It doesn’t work, it’s what I had before the current code.

  • 'limit' is from previous versions

  • @Marceloaymone I edited my question.

  • @Joaopaulo But in the documentation only talks about the limit.

  • @Joaopaulo The documentation is from version 2.x, if you are using 2.4 it is applicable yes.

  • 1

    @Jim, you set the paginator in the arrays of helpers? For paging to work properly, you need to set the helper, it assists in generating links.

  • @Marceloaymone Apparently it was in duplicate, but after fixing the problem remains the same.

  • I updated the answer again.

  • @Marceloaymone It’s the same, the line $this->Paginator->settings =$this->paginate;, it is mandatory for the Page to use the parameters in public $paginate?

  • When you define $this->paginate it is only a variable where you store the settings of PaginatorComponent, if you do not set anything, it will use the setting default, why it’s working when you disable it. $this->blaublau which does not matter, ie is not mandatory, but will work only in mode default.

  • @Marceloaymone Yes but $this->Paginator->settings is that will make the Page use these settings is not?

  • 1

    This, if you set directly would also work. Ex: $this->Paginator->settings['limit'] = 10; Which is equal to: $this->paginate = array('limit' => 10); and then: $this->Paginator->settings = $this->paginate; I think the documentation encourages you to use another array to separate the configuration array from the component call array.

  • Try to assign directly and then have it debugged to see what happens... maybe what is causing the problem is the ContainebleBehavior... It’s kind of problematic with the Paginator. Check it out: http://book.cakephp.org/2.0/en/core-libraries/behaviors/containable.html#using-Containable-with-pagination

  • @Marceloaymone I used the code $this->Paginator->settings['limit'] = 15; and seems to be working properly. What’s the problem then?

  • Did it work? Probably the array statement $paginate.

  • @Marceloaymone Trying to modify the options in the order of the list, I get the routes of the pages all disfigured again. Is there any way to solve the problem without it happening?

  • Updated the response.

  • @Marceloaymone Thank you so much for your support!

Show 13 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.