php yii 验证码问题

conroller 里面:

use yii\captcha\Captcha;

public function actions()
{
    return [
        'captcha' => [
            'class' => 'yii\captcha\CaptchaAction',
            'maxLength' => 5,
            'minLength' => 5
        ],
    ];
}

model 里面:

public $verifyCode; 
public function rules()
{
    return [
        [
            'verifyCode',
             'captcha',
        ],
    ];
}
public function attributeLabels()
{
    return [
        'verifyCode' => '', 
    ];
}    

表单里面:

use yii\captcha\Captcha;
<?php 
    echo Captcha::widget([
        'name'=>'captchaimg',
        'captchaAction'=>'login/captcha',
        'imageOptions'=>[
            'id'=>'captchaimg', 
            'title'=>'换一个', 
            'alt'=>'换一个',
            'style'=>'cursor:pointer;margin-left:25px;'
            ],
        'template'=>'{image}'
        ]);
?>

视图结果不显示验证:

clipboard.png

html 代码:

clipboard.png
为什么不显示呢?没有报错。

阅读 2.7k
3 个回答

具体报错是看src里的那个url.

你那个src怎么有个v1

视图可以这样:

src="<?=yii::$app->urlManager->createUrl('login/captcha')?>"
onclick= "this.src='<?=yii::$app->urlManager->createUrl('login/captcha')?>&d='+Math.random();"
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题