【发布时间】:2016-06-17 05:03:13
【问题描述】:
我只是 yii 2.0 框架的新手。我已经设置了 yii2.0 高级应用程序。我正在尝试在后端实现验证码。有人帮我查看以下文件框架中的联系页面文件:
@frontend/controllers/SiteController.php 尤其是“actions()”方法和“actionContact()”方法。
@frontend/models/ContactForm.php@frontend/views/site/contact.php
所以我在下面的文件中复制了以下代码:
-
@backend/views/sitelogin.php<?= $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>', ]); ?> -
@common/models/adminlogin.phpextend model class public $verifyCode;比在公共函数规则中声明()
['verifyCode', 'captcha'],
和
public function attributeLabels()
{
return [
'verifyCode' => 'Verification Code',
];
}
-
@backend/controllers/sitecontroller.php声明下面的函数'captcha' => [ 'class' => 'yii\captcha\CaptchaAction', 'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, ],
现在问题是验证码出现在登录页面上,但验证码的 iamge 没有出现,甚至提示我输入验证码错误,但没有验证码图像。
【问题讨论】: