yii2中验证码的使用--图片不显示
2015-10-09 10:36
489 查看
1.控制器中
public function actions()
{
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
2.模型中
要有一个验证码的字段$verifyCode
3.视图中
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
自动生成表单
页面中验证码代码
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
控制器中的权限可能导致验证码图片不显示,
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup','login'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
控制器中红线部分缺少则导致验证码不显示
public function actions()
{
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null,
],
];
}
2.模型中
要有一个验证码的字段$verifyCode
3.视图中
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use yii\captcha\Captcha;
自动生成表单
页面中验证码代码
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-3">{image}</div><div class="col-lg-6">{input}</div></div>',
]) ?>
控制器中的权限可能导致验证码图片不显示,
public function behaviors()
{
return [
'access' => [
'class' => AccessControl::className(),
'only' => ['logout', 'signup','login'],
'rules' => [
[
'actions' => ['signup'],
'allow' => true,
'roles' => ['?'],
],
[
'actions' => ['logout'],
'allow' => true,
'roles' => ['@'],
],
],
],
'verbs' => [
'class' => VerbFilter::className(),
'actions' => [
'logout' => ['post'],
],
],
];
}
控制器中红线部分缺少则导致验证码不显示
相关文章推荐
- java自动生成验证码插件-kaptcha
- 如何识别高级的验证码的技术总结第1/4页
- PHP 验证码不显示只有一个小红叉的解决方法
- asp汉字中文图片验证码
- PHP实现简单汉字验证码
- php 验证码制作(网树注释思想)
- C#验证码识别基础方法实例分析
- javascript点击才出现验证码
- node.js WEB开发中图片验证码的实现方法
- 验证码的三个常见漏洞和修复方法
- 声音验证码制作方法
- jsp 生成验证码代码
- ASP.NET图片处理三类经典问题
- javascript 验证码生成代码 推荐学习
- 轻轻绕过你的验证码并进行攻击
- php生成图形验证码几种方法小结
- PHP生成带有雪花背景的验证码
- asp下的一个很简单的验证码程序第1/3页
- jquery实现手机发送验证码的倒计时代码
- PHP5中GD库生成图形验证码(有汉字)