[英]cakephp3 giving undefined error for a defined variable
我的代码是-
$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数组。
您在闭包中使用$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]);}]]);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.