Recently read a Yii tutorial video, is in accordance with the version of 1.1, I want to use Yii2.0 framework also refer to his study development, the results found a lot of different, now talk about the verification code thing
First add an action to do verification code image display, the actual thing called the Captchaactive class
Public function actions () { return [ ' captcha ' + [ ' class ' = ' = ' yii\captcha\ Captchaaction ', ' height ' = +, ' width ' = +, ' minLength ' = 4, ' maxLength ' and ' = 4, ], ]; }
In the template file refer to the use of the following, specific or more read the document
Echo Captcha::widget ([' name ' = ' captchaimg ', ' captchaaction ' = ' login/captcha ', ' Options ' =>[' style ' = ' Cursor:pointer; ', ' id ' = ' captchaimg '], ' template ' = ' {image} ');?>
where ' captchaaction ' = ' Login/captcha ' is to be noted, his default is Site/captcha but if done under a module, it will automatically add a module prefix, such as my admin\, has not been shown at the beginning, Later found to be rote problem, but do not know where to change, look at the document for a long time.
And finally the validation,
In the model class of the Rules method, [' Captcha ', ' captcha ', ' message ' = ' captcha error ', ' captchaaction ' = ' admin/login/captcha '],
where ' captchaaction ' and ' admin/login/captcha ' also need to be set, the default is Site/captcha and here to absolute path of all, it does not automatically add module ID part.
The last one is validation.
$model $_post [' LoginForm ']; $model->validate ());
Of course, you can also get error messages for validation results.
Add in Template
Echo Html::error ($model, ' captcha ');?>
OK, more details of things to continue groping, and the 1.1 version of the different places quite a lot of. But it's familiar. The main document is in English, slightly creating a bit of a barrier.
Validation code for YII Framework 2.0