console\Controller prompt()

prompt() public method

Prompts the user for input and validates it

public string prompt ( $text, $options = [] )
$text string

Prompt string

$options array

The options to validate the input:

  • required: whether it is required or not
  • default: default value if no input is inserted by the user
  • pattern: regular expression pattern to validate user input
  • validator: a callable function to validate input. The function must accept two parameters:
    • $input: the user input to validate
    • $error: the error value passed by reference if validation failed.

An example of how to use the prompt method with a validator function.

$code = $this->prompt('Enter 4-Chars-Pin', ['required' => true, 'validator' => function($input, &$error) {
    if (strlen($input) !== 4) {
        $error = 'The Pin must be exactly 4 chars!';
        return false;
    }
    return true;
});
return string

The user input

doc_Yii
2016-10-30 16:54:47
Comments
Leave a Comment

Please login to continue.