yii 验证问题
yii 版本2.08
yii 验证码问题
1.模型里加入'verifyCode', 'captcha','message'=>'error','captchaAction' => 'test/captcha'
* 这个要配置指定的方法'captchaAction' => 'test/captcha'(这个是自己的控制器的)
* 2.在控制器里的actions 添加验证码的配置
* 'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'maxLength' => 4,
'minLength' => 4,
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
*
* 3.在前台的页面里调用验证码时加多一个'captchaAction' => 'test/captcha'(这个是自己的控制器的,跟上面的一致)配置
* 完成
自定义验证规则问题:
1.mode rules 如:['password','my(自定义的验证规则)'],
2.写这个方法
public function my($attribute , $params)
{
if(!preg_match("/^[\w]{6,20}$/" , $this->$attribute)){
$this->addError($attribute , '用户名必须为6~20的数字或字母');
}
}
说明:这个只能在提交后才能验证
3.在控制器里调用这个模型时
$model = new RegisterForm();
if($model->load(Yii::$app->request->post()) && $model->validate() )
这个$model->validate()必须在加入,我之前没有加入一直不成功
yii 验证问题的更多相关文章
- yii 验证器和验证码
http://www.yiiframework.com/doc/api/1.1/CCaptcha http://www.cnblogs.com/analyzer/articles/1673015.ht ...
- Yii - 验证和授权(Authentication and Authorization)
1. 定义身份类 (Defining Identity Class) 为了验证一个用户,我们定义一个有验证逻辑的身份类.这个身份类实现[IUserIdentity] 接口.不同的类可能实现不同的验证 ...
- YII 验证功能
YII 表单的验证可以在module目录下的xxx.php里面定义验证方法,设定需要验证的字段就行 //用户表单验证,在模型里面设置一个方法,具体表单验证规则 public functi ...
- yii验证系统学习记录,基于yiicms(二)
/** * Validates the specified object. * @param \yii\base\Model $model the data model being validated ...
- yii验证系统学习记录,基于yiicms(一)写的太长了,再写一篇(二)
项目地址:https://gitee.com/templi/yiicms 感谢七觞酒大神的付出,和免费分享.当然也感谢yii2的开发团队们. 项目已经安全完毕,不知道后台密码,这种背景下,后台无法进去 ...
- Yii 验证和消息
setFlash(), getFlash()可以完成验证成功后提示 <?php # 成功信息提示 Yii::app()->user->setFlash('success', &quo ...
- yii 验证用户名是否存在 array("name","unique",'message'=>'用户名已经存在'),
//验证用户名是否存在 array("name","unique",'message'=>'用户名已经存在'),
- YII 验证邮箱和QQ号码
//验证邮箱非空,和邮箱格式 //验证邮箱非空,和邮箱格式 array("email","e ...
- Yii 验证输入框是否输入的是数字
在对应的Model文件的rules中加入如下代码: array('age,phone', 'numerical', 'integerOnly'=>true,'message'=>'{att ...
随机推荐
- C# HttpWebRequest获取COOKIES
C# HttpWebRequest获取COOKIES byte[] bytes = Encoding.Default.GetBytes(_post); CookieContainer myCookie ...
- centos 7.0 安装nginx 1.117
php官方下载地址 http://cn2.php.net/downloads.php
- YII Install 安装
Download Yii is an open source project released under the terms of the BSD License. This means t ...
- 商业智能BI
参考资料: 7 款顶级开源 BI(商务智能)软件和报表工具
- telnet报“Unable to connect to remote host:Connection refused”错误
Linux下面telnet ip 端口号 报错误"Unable to connect to remote host:Connection refused"的时候,大部分是目标机的端 ...
- Android广播接收器BroadcastRceiver
一.使用BroadcastRceiver 1.创建BroadcastRceiver(MyRceiver),重写OnReceiver: public void onReceive(Context con ...
- sessionState详解
asp.net Session的默认时间设置是20分钟,即超过20分钟后,服务器会自动放弃Session信息. 当我们在asp.net程序中打开web.config的时候,可以看到一段如下的代码: A ...
- DataGrid控件使用
应用Binding显示后台数据 <UserControl x:Class="demo03.View.UserInfoList" xmlns=" ...
- [Machine Learning] logistic函数和softmax函数
简单总结一下机器学习最常见的两个函数,一个是logistic函数,另一个是softmax函数,若有不足之处,希望大家可以帮忙指正.本文首先分别介绍logistic函数和softmax函数的定义和应用, ...
- spring实例化bean的三种方式
公共使用的实体