PHP code example of vsevolod-ryzhov / yii2-code-validation

1. Go to this page and download the library: Download vsevolod-ryzhov/yii2-code-validation library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

vsevolod-ryzhov / yii2-code-validation example snippets


private $service;

public function __construct($id, $module, \vsevolodryzhov\yii2CodeValidation\Service $service, $config = [])
{
    parent::__construct($id, $module, $config);
    $this->service = $service;
}

public function actionChangeRequest()
{
    $form = new Form();

    if ($form->load(Yii::$app->request->post()) && $form->validate()) {
        // if form submitted and validated use "set" function to store form and get generated code
        $code = $this->service->set($form);
        // send $code here and then redirect to verify action
        return $this->redirect('/verify');
    }

    return $this->render('change', ['form' => $form]);
}

public function actionVerify()
{
    if (!$this->service->exists()) {
        // if nothing to verify - throw new Exception, redirect or do something else
    }

    // create CodeValidationForm (alidate()) {
        // clear all data on success
        $this->service->clear();
        // refresh or redirect to success page
        return $this->refresh();
    }

    return $this->render('verify', ['form' => $form]);
}

public function actionUpdate()
{
    $response = $this->service->renewCode();
}
$response->getDone()
$response->getWait()
$response->getCode()