CakePHP - Неопределенное свойство: View :: $ Paginator - PullRequest
1 голос
/ 15 июня 2011

У меня есть следующий контроллер, и я получаю ошибку

Notice (8): Undefined property: View::$Paginator [CORE/plugins/forum/views/galleries/index.ctp, line 5]

Контроллер:

<?php
class GalleriesController extends AppController {

    var $name = 'Galleries';

    function index() {
        $this->Gallery->recursive = 0;
        $this->set('galleries', $this->paginate());
    }
}
?>

Просмотр:

<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']; ?>&nbsp;</td>
        <td><?php echo $gallery['Gallery']['name']; ?>&nbsp;</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>

Ответы [ 2 ]

4 голосов
/ 15 июня 2011

Похоже, что PaginatorHelper не загружен. Обычно, когда вы звоните $this->paginate(), CakePHP автоматически загружает помощника. Вы можете явно загрузить его, добавив var $helpers = array('Paginator'); непосредственно под var $name = 'Galleries';, но что-то еще не так.

Метод paginate в классе Controller возвращается только один раз, прежде чем попасть в конец файла, где он добавляет PaginatorHelper, и если он не может найти модель. Должно появиться сообщение об ошибке «Controller :: paginate () - не удается найти модель Gallery в контроллере GalleriesController». Возможно, вы подавили ошибку, которая может объяснить, почему вы не видите проблему.

Попробуйте добавить ini_set('display_errors', true);, display_errors(E_ALL); и Configure::write('debug', 2); в действие перед любым вызовом, чтобы включить ошибки.

0 голосов
/ 28 февраля 2012

Я поставил этот код, он прекрасно работает.

    echo $paginator->first('First');
        echo "  ";
        if($paginator->hasPrev()){
            echo $paginator->prev('<<');
            echo "  ";`enter code here`
        }
    echo $paginator->numbers(array('modulus' => 2)); 
    echo "  ";
    if($paginator->hasNext()){ 
        echo $paginator->next('>>');
        echo "  ";
    }
    echo $paginator->last('Last');
    echo "  ";
...