I have the following controller, and I get the error
Notice (8): Undefined property: View::$Paginator [CORE/plugins/forum/views/galleries/index.ctp, line 5]
Controller:
<?php
class GalleriesController extends AppController {
var $name = 'Galleries';
function index() {
$this->Gallery->recursive = 0;
$this->set('galleries', $this->paginate());
}
}
?>
View:
<div class="galleries index">
<h2><?php __('Galleries');?></h2>
<table cellpadding="0" cellspacing="0">
<tr>
<th><?php echo $this->Paginator->sort('id');?></th>
<th><?php echo $this->Paginator->sort('name');?></th>
<th class="actions"><?php __('Actions');?></th>
</tr>
<?php
$i = 0;
foreach ($galleries as $gallery):
$class = null;
if ($i++ % 2 == 0) {
$class = ' class="altrow"';
}
?>
<tr<?php echo $class;?>>
<td><?php echo $gallery['Gallery']['id']; ?> </td>
<td><?php echo $gallery['Gallery']['name']; ?> </td>
<td class="actions">
<?php echo $this->Html->link(__('View', true), array('action' => 'view', $gallery['Gallery']['id'])); ?>
<?php echo $this->Html->link(__('Edit', true), array('action' => 'edit', $gallery['Gallery']['id'])); ?>
<?php echo $this->Html->link(__('Delete', true), array('action' => 'delete', $gallery['Gallery']['id']), null, sprintf(__('Are you sure you want to delete # %s?', true), $gallery['Gallery']['id'])); ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<p>
<?php
echo $this->Paginator->counter(array(
'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%', true)
));
?> </p>
<div class="paging">
<?php echo $this->Paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));?>
| <?php echo $this->Paginator->numbers();?>
|
<?php echo $this->Paginator->next(__('next', true) . ' >>', array(), null, array('class' => 'disabled'));?>
</div>
</div>
<div class="actions">
<h3><?php __('Actions'); ?></h3>
<ul>
<li><?php echo $this->Html->link(__('New Gallery', true), array('action' => 'add')); ?></li>
<li><?php echo $this->Html->link(__('List Images', true), array('controller' => 'images', 'action' => 'index')); ?> </li>
<li><?php echo $this->Html->link(__('New Image', true), array('controller' => 'images', 'action' => 'add')); ?> </li>
</ul>
</div>
It looks like the PaginatorHelper isn’t loaded. Usually, when you call
$this->paginate(), CakePHP automatically loads the helper. You could explicitly load it by addingvar $helpers = array('Paginator');directly below thevar $name = 'Galleries';but something else is wrong.The paginate method in the Controller class only returns once before getting to the bottom of the file where it add the PaginatorHelper and it’s if can’t find the model. It should trigger an error that reads “Controller::paginate() – can’t find model Gallery in controller GalleriesController”. You may have error suppressed which could explain why you’re not seeing the problem.
Try adding
ini_set('display_errors', true);,display_errors(E_ALL);, andConfigure::write('debug', 2);in the action, before any of the calls to enable errors.