gpt4 book ai didi

php - cakephp3 为定义的变量给出未定义的错误

转载 作者:行者123 更新时间:2023-11-29 11:57:06 25 4
gpt4 key购买 nike

我的代码是 -

$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]);}]]);

关于php - cakephp3 为定义的变量给出未定义的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33031752/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com