Pagination always shows 20 images

3

I'm making a gallery that uses Pagination from CakePHP. The problem is that I only want to show 15 images per page, but regardless of the value I put in public $paginate , at the limit, 20 images are always shown. With the $this->Paginator->settings =$this->paginate; line uncommented this works, but causes the routes that contain the page numbers to not work correctly. DebugKit also shows that the Soptions array 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>
    
asked by anonymous 27.05.2014 / 19:16

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( ... )
);
    
27.05.2014 / 22:47