2012-12-29 4 views
-1

je souhaite utiliser paginer dans le modèle, mais quand j'insérer la fonction paginate, je reçois cette erreur:cakephp2: utilisation paginer dans le modèle

Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'paginate' at line 1

Mon code:

<?php 
class Post extends AppModel 
{ 
    public function get_posts() 
    { 
     $this->paginate = array(
      'fields' => array('Post.id', 'Post.title', 'Post.created'), 
      'limit' => 3, 
      'order' => array(
       'Post.created' => 'DESC' 
      )   
     ); 

     $posts = $this->paginate('Post'); 

     return $posts; 
    } 

Quel est le problème avec mon code?

Répondre

3

paginate() est une méthode de contrôleur et non une méthode de modèle.