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?
– Joao Paulo
@Joaopaulo It was what I was using before maxLimit, and it also doesn’t work.
– Jim
@Joaopaulo I edited my question.
– Jim