cakephp – Pagination always shows 20 images

Question:

I'm making a gallery that uses 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 causes routes that contain page numbers to not work correctly. DebugKit also shows that the Soptions array is empty. Why is this happening? Is there any way to make this work with this commented out 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>

Answer:

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 code above would result in 10 pages, with 100 results in total.

Or like this:

$this->Paginator->settings = array(
        'SeuModel' => array(
                'limit' => 20,
                'maxLimit' => 100,
                'order' => array('SeuModel.campo' => 'ASC') // Por exemplo
        ),
        'OutroModel' => array( ... )
);
Scroll to Top