gpt4 book ai didi

php - 如何在 yii find() 中输入条件?

转载 作者:行者123 更新时间:2023-11-29 02:54:00 26 4
gpt4 key购买 nike

我有两个表AccountUser

Account 表包含account_id, username, password

User 表包含 user_idaccount_idfirst_namelast_name

我想要的是 yii 显示登录用户的 user 表的内容,所以我使用了这段代码

$user= Yii::app()->user->id; //to get the account_id of user logged in
$userModel = User::model()->find(array('condition'=>'account_id' == $user));
//to find data in the user table with the account_id similar to the
//account_id of the one logged in
print_r($userModel); //to check if I got the correct data

但出于某种原因,无论谁登录,print_r($userModel) 都会返回带有 account_id == 1

的数据

请帮忙:/

最佳答案

如果您使用的是 Yii 1,您可以尝试使用 findByAttribute

$userModel = User::model()->findByAttributes(array('account_id'=>$user));

关于php - 如何在 yii find() 中输入条件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32696236/

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