There are rules (yii1) in it a rule
['lastname, firstname, midname', 'length', 'max' => 80] How to check if there is a user with the same name and surname ?:
Use a custom validator in this case:
['lasttname', 'checkUnique'], And below in the file validator method:
public function checkUnique($attribute, $params) { $user = Users::model()->findByAttributes([ 'lastname' => $this->lastname, 'firstname' => $this->firstname, 'midname' => $this->midname, ]); if ($user !== null) { $this->addError($attribute, 'Такой пользователь уже существует'); } } Source: https://ru.stackoverflow.com/questions/588013/
All Articles