[rtl][font="Tahoma"]سلام
فرض کنید ما کد زیر رو توی yii2 داریم:[/font][/rtl]
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".');
}
}
}
[font="Tahoma"][rtl]
چظوری می تونم به validateCountry پارامتر بفرستم؟
[/rtl][/font]