码迷,mamicode.com
首页 > 其他好文 > 详细

yii2 unique 验证

时间:2017-06-24 16:15:24      阅读:154      评论:0      收藏:0      [点我收藏+]

标签:date   model   过程   class   load   mode   func   oncreate   email   

开发过程中会用到检测用户名或手机号或邮箱是否唯一。

在model的rules中加入

[[‘email‘],‘unique‘],

在view中

<?php $form = ActiveForm::begin([‘enableAjaxValidation‘ => true]); ?>

在controller中

public function actionCreate()
    {
        $model = new User();
        if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) {
            Yii::$app->response->format = Response::FORMAT_JSON;
            return ActiveForm::validate($model);
        }
}

即可。

yii2 unique 验证

标签:date   model   过程   class   load   mode   func   oncreate   email   

原文地址:http://www.cnblogs.com/joystrong/p/7073525.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!