Home  >  Article  >  PHP Framework  >  How to generate verification code in yii2

How to generate verification code in yii2

爱喝马黛茶的安东尼
爱喝马黛茶的安东尼Original
2019-12-09 13:05:322862browse

How to generate verification code in yii2

1. Add the code in the controller

public function actionCaptcha(){
    $c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
    $c->getVerifyCode(true);
    return $c->run();
}

2. Call the verification code through the following method

$c = Yii::createObject('yii\captcha\CaptchaAction', ['__captcha', $this]);
$code = $c->getVerifyCode();

$code is generated before Verification code

Note: $this represents the current controller, this method is only suitable for use in one controller.

3. Front-end call:

Write a

PHP Chinese website has a large number of free Yii introductory tutorials, everyone is welcome to learn!

The above is the detailed content of How to generate verification code in yii2. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn