【发布时间】:2017-11-08 11:57:22
【问题描述】:
我是 Yii 的新手,我很难理解一些事情。
我有这个功能的模型:
public static function findNonGeo()
{
$query = new CallerIdentityQuery(get_called_class());
$query->select([
'cidref', 'caller_id', 'expiry', 'conf_call',
'type', 'redirect', 'destination', 'status', 'start_date',
'statusDesc' => new \yii\db\Expression("CASE status
WHEN 0 THEN 'Deactivated'
WHEN 1 THEN 'Active'
WHEN 2 THEN 'Inactive'
WHEN 3 THEN 'Unregistered'
ELSE 'Permanently Deleted' END")])
->where(['status' => '1'])
->andWhere(['type' => 'N'])
->andWhere(['custref' => Yii::$app->user->identity->typedIdentity->getId()]);
return $query;
}
在我的控制器中,我这样称呼这个方法:
$model = CallerIdentity::findNonGeo()->where(['cidref' => $id])->one();
但是当返回数据时它就像它只是忽略了
->andWhere(['type' => 'N'])
因为我可以查看非“N”类型的记录。 所以我不得不在我的控制器中做,也许我做错了什么或者只是不理解它,但我不明白:
$model = CallerIdentity::findNonGeo()->where(['cidref' => $id])->andWhere(['type'=>'N'])->one();
使用 findOne($id) 时的另一件事:
$model = CallerIdentity::findOne($id);
返回空值。
不胜感激任何形式的解释/信息。
【问题讨论】:
标签: activerecord yii