如何从数据库中获取phone号码和用户名(PHP, Yii1.1)
How to get phone number and username from database (PHP, Yii1.1)
我正在尝试将两个表连接在一起并获取用户的 phone 号码用户名,当 oncallduty 为 true 时。
public function actionGetPhone($name) {
$userHasTeam = new UserHasTeam();
$criteria = new CDbCriteria();
$criteria->with = array('teams', $userHasTeam);
$criteria->together = true;
$criteria->addCondition($userHasTeam->oncallduty = 1);
$model = User::model()->find($criteria);
Yii::log(print_r($model, true));
echo $model['username'];
echo $model['mobile'];
}
这就是我目前所拥有的。所有这些都打包在一个可以通过 GET 请求调用的函数中。
我找到了解决办法。我不知道为什么,但我试图连接的模型以某种方式获得了别名。为此,我根本无法连接到 table。下面是我做的方法
$criteria = new CDbCriteria();
$criteria->with = array('teams');
$criteria->addCondition('teams.name = :teams');
$criteria->addCondition('teams_teams.oncallduty = 1');
$criteria->params = array(':teams'=>$name);
$model = User::model()->find($criteria);
echo "This is the mobile of user on duty: ".$model['mobile'];
我正在尝试将两个表连接在一起并获取用户的 phone 号码用户名,当 oncallduty 为 true 时。
public function actionGetPhone($name) {
$userHasTeam = new UserHasTeam();
$criteria = new CDbCriteria();
$criteria->with = array('teams', $userHasTeam);
$criteria->together = true;
$criteria->addCondition($userHasTeam->oncallduty = 1);
$model = User::model()->find($criteria);
Yii::log(print_r($model, true));
echo $model['username'];
echo $model['mobile'];
}
这就是我目前所拥有的。所有这些都打包在一个可以通过 GET 请求调用的函数中。
我找到了解决办法。我不知道为什么,但我试图连接的模型以某种方式获得了别名。为此,我根本无法连接到 table。下面是我做的方法
$criteria = new CDbCriteria();
$criteria->with = array('teams');
$criteria->addCondition('teams.name = :teams');
$criteria->addCondition('teams_teams.oncallduty = 1');
$criteria->params = array(':teams'=>$name);
$model = User::model()->find($criteria);
echo "This is the mobile of user on duty: ".$model['mobile'];