
1、在控制器添加一下代码
public function actionCaptcha(){
$c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
$c->getVerifyCode(true);
return $c->run();
}
2、通过以下方法调用验证码
$c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
$code = $c->getVerifyCode();
$code就是之前生成的验证码
注意:$this代表当前控制器,此方法只适合在一个控制器使用。
3、前端调用:
写个
PHP中文网,有大量免费的Yii入门教程,欢迎大家学习!











