0

I wrote a function that creates a 6-digits number.

how can I validate this number manually without using models in yii2?

Andrei
  • 36,642
  • 31
  • 139
  • 196
mojtaba.sln
  • 51
  • 1
  • 7

1 Answers1

0

i think it's useful:

<?php
  public function actionValidation(){
    $model = new \yii\base\DynamicModel(['number']);
    $model->addRule('number', 'integer', ['message'=>'should be a number']);
    $model->number = $this->yourFunction();
    Yii::$app->response->format = Response::FORMAT_JSON;
    return ActiveForm::validate($model);
 }

  public function yourFunction(){
    return 6-digits-number;
 }
?>
SADi
  • 195
  • 1
  • 12