我有两个表:帖子和喜欢
我正在尝试列出当前登录用户喜欢的帖子。该方法如下所示:
$following = $this->Follower->listFollowing($this->Auth->user('id'));
$this->paginate = array('limit'=>20,'conditions'=>array('Post.id'=>array($following['Follower']['post_id']),'Post.status'=>array(1,2)),'order'=>array('Post.datetime'=>'desc'),
'contain'=>array('User','Answer'=>array('User'),'Tag'));
$this->set('posts',$this->paginate());
所以基本上我要做的是首先查询以下(喜欢)表以获取与用户匹配的所有行,然后在我的查找查询中使用这个帖子 ID 数组来列出查询中的帖子。
Follower 模型中的 listFollowing 方法如下所示:
public function listFollowing($user_id)
{
return $this->find('all', array(
'conditions' => array('Follower.user_id'=>$user_id)
));
}
我目前收到如下错误:Undefined index: Follower [APP/Controller/PostsController.php, line 94]
所以我会假设我在查找查询中尝试从以下内容传递帖子 ID 列表的方式不正确。
任何人都可以帮忙吗?谢谢
编辑:对 $following 进行调试会给出:
array(
(int) 0 => array(
'Follower' => array(
'id' => '4',
'user_id' => '6',
'post_id' => '136'
),
'User' => array(
'password' => '*****',
'id' => '6',
'username' => 'driz',
'email' => '######'
),
'Post' => array(
'id' => '136',
'user_id' => '8',
'datetime' => '2012-09-11 15:49:52',
'modified' => '2012-09-16 15:31:38',
'title' => 'Test Content',
'slug' => 'Test_content',
'content' => 'Test Content',
'status' => '1'
)
),
(int) 1 => array(
'Follower' => array(
'id' => '5',
'user_id' => '6',
'post_id' => '133'
),
'User' => array(
'password' => '*****',
'id' => '6',
'username' => 'driz',
'email' => '######'
),
'Post' => array(
'id' => '134',
'user_id' => '8',
'datetime' => '2012-09-11 15:49:52',
'modified' => '2012-09-16 15:31:38',
'title' => 'Test Content 2',
'slug' => 'Test_content_2',
'content' => 'Test Content 2',
'status' => '1'
)
)
)