how to pass parameter to custom validator

hi

for example we have this :




use yii\base\Model;


class MyForm extends Model

{

    public $country;

    public $token;


    public function rules()

    {

        return [

            // an inline validator defined as the model method validateCountry()

            ['country', 'validateCountry'],


            // an inline validator defined as an anonymous function

            ['token', function ($attribute, $params) {

                if (!ctype_alnum($this->$attribute)) {

                    $this->addError($attribute, 'The token must contain letters or digits.');

                }

            }],

        ];

    }


    public function validateCountry($attribute, $params)

    {

        if (!in_array($this->$attribute, ['USA', 'Web'])) {

            $this->addError($attribute, 'The country must be either "USA" or "Web".');

        }

    }

}



how to pass parameter to validateCountry?


['country', 'validateCountry', 'myParameter' => 'value']




  public function validateCountry($attribute, $params)

    {

        if (!in_array($this->country, ['USA', 'Web'])) {

            $this->addError($attribute, 'The country must be either "USA" or "Web".');

        }

    }



http://barnamenevis.org/showthread.php?486874-ارسال-پارامتر-به-custom-validator&p=2178525&viewfull=1#post2178525