CakePHP:SQLSTATE[42S22]:未找到列:1054未知列';张贴';在';其中条款&#


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

我有以下代码来显示一个帖子列表,其中还包含来自作者用户和配置文件的信息。配置文件表没有到帖子的直接链接,而是通过用户表进行链接。

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'

你知道这里出了什么问题吗?感谢

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

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