2016-10-19 8 views
1

ログインページにCaptcha認証を追加します。しかし、エラーがあり、キャプチャ画像が表示されず、キャプチャ画像を表示しようとしたときhttp://xxx.yii2/site/captcha?v=5806eb0c3aa05、以下のエラー表示Yii2 captcha画像が表示されない

http://xxx.yii2/site/captcha?v=5806ce094fa84」にはエラーがあるため表示できません。

は以下

class SiteController extends Controller { 
    public function behaviors() 
    { 
    return [ 
     'access' => [ 
      'class' => AccessControl::className(), 
      'only' => ['logout','resetPassword'], 
      'rules' => [ 
       [ 
        'actions' => ['logout','resetpassword'], 
        'allow' => true, 
        'roles' => ['@'], 
       ], 
      ], 
     ], 
     'verbs' => [ 
      'class' => VerbFilter::className(), 
      'actions' => [ 
       'logout' => ['post'], 
      ], 
     ], 
    ]; 
} 

public function actions() 
{ 
    return [ 
     'error' => [ 
      'class' => 'yii\web\ErrorAction', 
     ], 
     'captcha' => [ 
      'class' => 'yii\captcha\CaptchaAction', 
      'fixedVerifyCode' => YII_ENV_TEST ? 'testme' : null, 
     ], 
    ]; 
} 

LoginFormコントローラ

class LoginForm extends Model { 
    public $username; 
    public $password; 
    public $rememberMe = true; 
    public $verifyCode; 

    private $_user = false; 

    const ERROR_NONE=0; 
    const ERROR_USERNAME_INVALID=1; 
    const ERROR_USERNAME_LOCKED = 3; 
    const ERROR_USERNAME_INACTIVE = 4; 
    const ERROR_PASSWORD_INVALID=2; 

    public $role_id; 
    public $salt; 
    public $_id; 
    private $_identity; 

    /** 
    * @return array the validation rules. 
    */ 
    public function rules() 
    { 
    return [ 

     [['username', 'password'], 'required'], 
     ['rememberMe', 'boolean'], 
     ['username','validateMember'], 
     ['password', 'validatePassword'], 
     ['verifyCode', 'captcha'], 

    ]; 
    } 

ログインフォームビュー

<?php $form = ActiveForm::begin([ 
    'id' => 'login-form', 
    'options' => ['class' => 'form-horizontal'], 
    'fieldConfig' => [ 
     'template' => "{label}\n<div class=\"col-lg-3\">{input}</div>\n<div class=\"col-lg-8\">{error}</div>", 
     'labelOptions' => ['class' => 'col-lg-1 control-label'], 
    ], 
]); ?> 

    <?= $form->field($model, 'username') ?> 

    <?= $form->field($model, 'password')->passwordInput() ?> 

    <?= $form->field($model, 'verifyCode')->widget(Captcha::className()) ?> 

    <?= $form->field($model, 'rememberMe')->checkbox([ 
     'template' => "<div class=\"col-lg-offset-1 col-lg-3\">{input} {label}</div>\n<div class=\"col-lg-8\">{error}</div>", 
    ]) ?> 

    <div class="form-group"> 
     <div class="col-lg-offset-1 col-lg-11"> 
      <?= Html::submitButton('<i class="fa fa-sign-in fa-fw"></i> Login', ['class' => 'btn btn-primary', 'name' => 'login-button']) ?> 
     </div> 
    </div> 

<?php ActiveForm::end(); ?> 

答えて

1

チェックこの私のSiteControllerです。

CaptchaActionには、GD2拡張機能またはImageMagick PHP拡張機能が必要です。

参照:Class yii\captcha\CaptchaAction

は問題のもう一つの可能​​な理由は、間違ったアクションが指定されています。これを解決するには、モデルとウィジェットの両方で手動かどうかを指定する必要があります。

モデル:

['verifyCode', 'captcha', 'captchaAction' => 'site/captcha'] 

ウィジェット:

<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [ 
    'captchaAction' => 'site/captcha' 
]) ?> 
+0

I)が(キャプチャ:: checkRequirementsを使用してチェックし、imagickを持っています。 – kasmawati

+0

特定のエラーが何であるかを取得すると、問題を理解するのがはるかに簡単になります。 デバッグパネルを調べる必要があります。左上隅には、現在表示されているリクエスト以外のリクエストを選択できるセレクタがあります。 –

+0

私が得る唯一のエラーは - 与えられたURLをロードできませんでした – kasmawati

関連する問題