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>