$controllerID = Yii::$app->controller->id //获取当前的控制器名
$actionID = Yii::$app->controller->action->id; //获取当前的方法名
Yii2.0中验证码的使用
model层
public $verifyCode;
public function rules()
{
return [
['verifyCode', 'required','message' => '不能为空'],
['verifyCode', 'captcha'],
];
}
控制器层
public function actions() {
return [
'captcha' => [
'class' => 'yii\captcha\CaptchaAction',
'height' => 50,
'width' => 60,
'minLength' => 5,
'maxLength' => 5,
],
];
}
视图层
<?= $form->field($model, 'verifyCode')->widget(Captcha::className(), [
'template' => '<div class="row"><div class="col-lg-6">{input}</div><div class="col-lg-3">{image}</div></div>',
]) ?>