YII 2.0 Captcha Implementation problem

Hello Team,

I am first time working on yii2.0. I have setup yii2.0_advanced_app. I have one frontend and on admin backend. I want to have captcha at my admin login. Can someone help me with this. Till now I have tried something from this page "“http://www.yiiframework.com/doc-2.0/yii-captcha-captcha.html” but it didn’t helpout.

I have copied this code in my admin login.php

<?= $form->field($model, ‘captcha’)->widget(\yii\captcha\Captcha::classname(), [

// configure additional widget properties here

]) ?>

I got error. Attached is screenshot for this error. Many other link on Google say we need to set path for captcha. If yes is there any methood to do so. Like in Joomla we have defined methood to declare paths.7003

yii_captcha.jpg

The error message reads that you forgot to add ‘captcha’ attribute to your AdminLoginForm model.

Can you please, help me what i have to do? I am really new bee so, don’t have an idea.

You can see how to use captcha in the "Contact" page of the frontend.

Take a close look at the following source codes:

  1. @frontend/controllers/SiteController.php

especially "actions()" method and "actionContact()" method.

  1. @frontend/models/ContactForm.php

  2. @frontend/views/site/contact.php

And, if you think that you are a newbie, you should read through the definitive guide at any cost.

http://www.yiiframework.com/doc-2.0/guide-index.html

@frontend/controllers/SiteController.php especially &quot;actions()&quot; method and &quot;actionContact()&quot; method.


@frontend/models/ContactForm.php


@frontend/views/site/contact.php

So i have copied follwing code in below file :

@backend/views/sitelogin.php


field(&#036;model, 'verifyCode')-&gt;widget(Captcha::className(), [ 'template' =&gt; '{image}{input}', ]) ?&gt;





@common/models/adminlogin.php





extend model class public &#036;verifyCode;





than declare in public function rules()





['verifyCode', 'captcha'],

and

public function attributeLabels()

{


    return [


        'verifyCode' =&gt; 'Verification Code',


    ];


}





@backend/controllers/sitecontroller.php declare below function





'captcha' =&gt; [ 'class' =&gt; 'yii&#092;captcha&#092;CaptchaAction', 'fixedVerifyCode' =&gt; YII_ENV_TEST ? 'testme' : null, ],

now the issue is captcha appear on login page but iamge of captcha is not appearing it even prompt me error to enter captcha but no captcha image.

Check "actions()" method of the SiteController.

Well, I have fixed it. Thanks, for your help :)