tags:

views:

29

answers:

1

Hi all,

I am following the instruction in the cookbook web site of CakePHP: link text

And got this error:

Undefined variable: paginator [APP/views/post/index.ctp, line 46]

I am not sure if $paginator is a built-in variable in cakePHP 1.26.

In my Controller, I have this:

        $this->set('posts', $this->Site1->find('all', array('conditions'=>array('Post.zero'=>'0'), 'order'=>array('Post.created DESC'), 'limit'=>'3')));

And in the .ctp file, I have this:

<table>
        <tr><td>
       <?php echo $paginator->numbers(); ?>
<?php
    echo $paginator->prev('Previous', null, null);
    echo $paginator->next(' Next', null, null);
?> 

        </td></tr>       

       </table>

How do I know if Site1 or Post is not the default Model in a controller?

+1  A: 

This is your code:

$this->paginate = array('order'=>array('Post.created DESC'), 'limit'=>3);
$this->set('posts', $this->paginate(null, array('Post.zero'=>'0')));

If the Site1 is not the default Model in that controller, then use

$this->set('posts', $this->paginate($this->Site1, array('Post.zero'=>'0')));

Try to use bake console - it's much easier instead of wild guessing :)

Nik
How to set the limit value and DESC order in your suggested code, Nik?
The first parameter of paginate needs to be a string, e.g. 'Post'. Although it can be null, presumably defaulting to the current model, I *never* do this, but always specify the modelname as it makes later comprehension of the code far easier, especially with complex controllers.WRT the DESC order, DESC *is* the order. The alternative is ASC.
Leo
Thank you for the help, Leo.