2012-01-29 61 views
0

我有以下代碼來顯示也包含來自作者用戶和配置文件的信息的帖子列表。個人資料表沒有直接鏈接到帖子,並通過用戶錶鏈接。CakePHP:SQLSTATE [42S22]:找不到列:1054'where子句'中的'Post'未知列

public function index() 
{ 
    $posts = $this->Post->find('all',null,array('contain'=>array('User'=>'Profile'))); 

    $this->set('posts',$this->paginate($posts)); 
} 

但是我得到這個錯誤:

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Post' in 'where clause' 

任何想法,這裏有什麼問題嗎?謝謝

回答

6

你不應該find然後paginate; paginate本身調用模型的find方法來獲取當前頁面的行。將您的代碼更改爲:

public function index() 
{ 
    $this->paginate = array(
     'contain'=> array('User'=>'Profile') 
    ); 

    $this->set('posts',$this->paginate()); 
} 
相關問題