CakePHP:SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'Post'

Cam*_*ron 0 php cakephp

我有以下代码来显示帖子列表,其中还包含作者用户和个人资料的信息.配置文件表没有直接链接到帖子,并通过用户表链接.

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

    $this->set('posts',$this->paginate($posts));
}
Run Code Online (Sandbox Code Playgroud)

但是我收到此错误:

 SQLSTATE[42S22]: Column not found: 1054 Unknown column 'Post' in 'where clause'
Run Code Online (Sandbox Code Playgroud)

有什么想法这里的问题是什么?谢谢

ori*_*ori 6

你不应该find,然后paginate; paginate它本身调用模型的find方法来获取当前页面的行.将您的代码更改为:

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

   $this->set('posts',$this->paginate());
}
Run Code Online (Sandbox Code Playgroud)