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.前端调用:
写个<img src=此action访问网址+随机字符串,防止缓存

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-31
  • 2021-12-22
  • 2021-11-01
  • 2022-02-16
  • 2021-11-14
  • 2021-10-30
猜你喜欢
  • 2021-10-07
  • 2022-01-16
  • 2022-12-23
  • 2021-11-03
相关资源
相似解决方案