PHP code example of kdn / yii2-domain-validator

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

    

kdn / yii2-domain-validator example snippets




namespace app\models;

use kdn\yii2\validators\DomainValidator;
use Yii;
use yii\base\Model;

class YourCustomModel extends Model
{
    public $domain;

    public function rules()
    {
        return [
            ['domain', DomainValidator::class],
            /*
            or with custom options: enable IDN and forbid URLs
            [
                'domain',
                DomainValidator::class,
                'enableIDN' => true,
                'allowURL' => false,
            ],
            */
        ];
    }

    public function attributeLabels()
    {
        return [
            'domain' => Yii::t('app', 'Domain Name'),
        ];
    }
}

   public function rules()
   {
       return [
           ['domain', 'url'],
           ['domain', DomainValidator::class],
       ];
   }
   
sh
php composer.phar