yii\captcha\CaptchaAction::getVerifyCode PHP Method

getVerifyCode() public method

Gets the verification code.
public getVerifyCode ( boolean $regenerate = false ) : string
$regenerate boolean whether the verification code should be regenerated.
return string the verification code.
    public function getVerifyCode($regenerate = false)
    {
        if ($this->fixedVerifyCode !== null) {
            return $this->fixedVerifyCode;
        }
        $session = Yii::$app->getSession();
        $session->open();
        $name = $this->getSessionKey();
        if ($session[$name] === null || $regenerate) {
            $session[$name] = $this->generateVerifyCode();
            $session[$name . 'count'] = 1;
        }
        return $session[$name];
    }

Usage Example

 public function getVerifyCode($regenerate = false)
 {
     if (!$this->regenerateIfAjax) {
         $request = Yii::$app->getRequest();
         if ($request->getIsAjax() && !$request->getQueryParam(self::REFRESH_GET_VAR)) {
             $regenerate = false;
         }
     }
     return parent::getVerifyCode($regenerate);
 }