PHP code example of raoptimus / yii2-composite-validator
1. Go to this page and download the library: Download raoptimus/yii2-composite-validator 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/ */
raoptimus / yii2-composite-validator example snippets
class StringDefaultValidator extends CompositeValidator
{
/** @var string */
public $defaultValue;
/** @var int */
public $max;
/** @var int */
public $min;
/**
* @inheritdoc
*/
protected function validators(): array
{
return [
[StringValidator::class, 'max' => $this->max, 'min' => $this->min],
[DefaultValueValidator::class, 'value' => $this->defaultValue],
];
}
}
class DefaultForm extends Model
{
/**
* @var string
*/
public $field;
/**
* @inheritdoc
*/
public function rules(): array
{
return [
[['field'], StringDefaultValidator::class, 'max' => 50, 'defaultValue' => 'test'],
];
}
}
$form = new DefaultForm();
$form->validate();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.