dongzhun4898 2016-05-03 08:28
浏览 371
已采纳

Yii deleteAll()记录条件

I've set up a log in process where a verification code is generated, and when successful, is then removed. However, i want to make sure that if there's multiple verification codes for the same user, upon log in success, delete all records for that user.

Here's my code

if ($model->validate() && $model->login()) {

    //delete this verification code
    $verificationCode->delete();
    //delete all existing codes for user_id
    VerificationCode::model()->deleteAll('user_id',$user->id);

    Yii::app()->user->setReturnUrl(array('/system/admin/'));

    $this->redirect(Yii::app()->user->returnUrl);
}

However, this seems to just delete all the records, regardless on different user_id's in table. Can anyone see where I'm going wrong?

  • 写回答

4条回答 默认 最新

  • doupo2633 2016-05-03 09:05
    关注

    Seems you call the function delete() in wrong way ... try passing value this way

    VerificationCode::model()->deleteAll(['user_id' => $user->id]);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部