PHP code example of codeonyii / yii2-at-least-validator

1. Go to this page and download the library: Download codeonyii/yii2-at-least-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/ */

    

codeonyii / yii2-at-least-validator example snippets


    composer 

use codeonyii\yii2validators\AtLeastValidator;

class MyModel extends Model
{
...
    public function rules()
    {
        // see examples below
    }
...

     // in rules()
     return [
         ['phone', AtLeastValidator::className(), 'in' => ['phone', 'email']],
     ];

     // in rules()
     return [
         [['facebook', 'instagram'], AtLeastValidator::className(), 'in' => ['facebook', 'linkedin', 'instagram'], 'min' => 2],
     ];

     // in the rules()
     // please note the exclamation mark. It will avoid the pk attribute to be massively assigned.
     return [
         ['!id', AtLeastValidator::className(), 'in' => ['attr1', 'attr2', 'attr3']], // where `id` is the pk
     ];

     // in the view, show all errors in the summary:
     ...
     echo yii\helpers\Html::errorSummary($model, ['class' => ['text-danger']]);

     // OR, to show only `id` errors:
     echo yii\helpers\Html::error($model, 'id', ['class' => ['text-danger']]);