我的代码是 -
$user_id = 1;
$users = $this->UserModel->getUser($user_id);
$get_result = $this->Actionmodel->find('all', [
'conditions' => ['id IN' => $ids],
'contain' => [
'Rank' => function ($q) {
return $q
->select(['id', 'user_id', 'description'])
->where([
'status' => 1,
'user_id NOT IN' => $users
]);
}
]
]);
给出错误未定义的用户。而它的打印user_id数组。
答案 0 :(得分:1)
你在封闭中使用$users
而没有在use
中指定它...就像这样:
$get_result = $this->Actionmodel->find('all',[
'conditions'=>['id IN' => $ids],
'contain'=>['Rank' => function ($q) use ($users) {
return $q
->select(['id','user_id','description'])->where(['status' => 1,'user_id NOT IN' => $users]);}]]);