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、前端调用:
写个,有大量免费的yii入门教程,欢迎大家学习!
以上就是yii2怎么样生成验证码的详细内容。
