鍍金池/ 問(wèn)答/PHP/ php yii 驗(yàn)證碼問(wèn)題

php yii 驗(yàn)證碼問(wèn)題

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'=>'換一個(gè)', 
            'alt'=>'換一個(gè)',
            'style'=>'cursor:pointer;margin-left:25px;'
            ],
        'template'=>'{image}'
        ]);
?>

視圖結(jié)果不顯示驗(yàn)證:

clipboard.png

html 代碼:

clipboard.png
為什么不顯示呢?沒(méi)有報(bào)錯(cuò)。

回答
編輯回答
旖襯

你那個(gè)src怎么有個(gè)v1

2017年10月22日 04:45
編輯回答
柒槿年

具體報(bào)錯(cuò)是看src里的那個(gè)url.

2017年3月26日 04:40
編輯回答
萌二代

視圖可以這樣:

src="<?=yii::$app->urlManager->createUrl('login/captcha')?>"
onclick= "this.src='<?=yii::$app->urlManager->createUrl('login/captcha')?>&d='+Math.random();"
2017年11月8日 16:31