looks like you are doing a find not paginate, try something like this:
> public function news() {
> $this->set('posts', $this->paginate ('Post'));
> }
or :
public function news() {
$this->paginate = array(
'limit' => 10,
'order' => array('Post.title' => 'ASC'),
);
$posts = $this->paginate('Post');
$this->set(compact('posts'));
}
also no need to load Paginator helper here:
> public $helpers = array('Html', 'Form', 'Paginator');
The paginator will load that for you automatically.
Andras Kende
http://www.kende.com
On Jan 12, 2012, at 6:10 PM, Chooch Schubert wrote:
> I have followed the 2.0 book to add pagination to a controller/view. I
> get the paginate controls and they are rendering correctly (they
> *think* I'm doing things like next page and sort when I click on the
> links since they change their counts and links) however the data
> returned isn't paginated.
>
> I should only be seeing 10 posts, but I am getting all posts in the
> database (about 30) no matter what I click on.
>
> Any pointers?
>
> The code in the PostsController.php looks like:
> <?php
> class PostsController extends AppController {
> public $name = 'Posts';
> public $helpers = array('Html', 'Form', 'Paginator');
> public $components = array('Session');
>
> public $paginate = array(
> 'limit' => 5,
> 'order' => array(
> 'Post.title' => 'asc'
> )
> );
>
> public function news() {
> $this->paginate ('Post');
> $this->set('posts', $this->Post->find('all'));
> }
>
> The code in the view looks like:
> <table>
> <tr>
> <th width=25%><?php echo $this->Paginator->sort('title',
> 'Title'); ?></th>
> <th><?php echo $this->Paginator->sort('body', 'Content'); ?></
> th>
> </tr>
> <?php foreach ($posts as $post): ?>
> <tr>
> <td><?php echo $post['Post']['title']; ?> </td>
> <td><?php echo $post['Post']['body']; ?> </td>
> </tr>
> <?php endforeach; ?>
> </table>
>
> <?php
> // Shows the page numbers
> echo $this->Paginator->numbers();
>
> // Shows the next and previous links
> echo $this->Paginator->prev('« Previous', null, null, array('class' =>
> 'disabled'));
> echo $this->Paginator->next('Next »', null, null, array('class' =>
> 'disabled'));
>
> // prints X of Y, where X is current page and Y is number of pages
> echo $this->Paginator->counter();
> ?>
>
> --
> Our newest site for the community: CakePHP Video Tutorials
> http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help
> others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> [email protected] For more options, visit this group at
> http://groups.google.com/group/cake-php
--
Our newest site for the community: CakePHP Video Tutorials
http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others
with their CakePHP related questions.
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at
http://groups.google.com/group/cake-php