K
K
khodos_dmitry2018-11-04 17:30:26
Yii
khodos_dmitry, 2018-11-04 17:30:26

Why is the data constantly not being validated?

Model:

public function rules() {
    return [
      ['email', 'email'],
      ['name', 'myRule'],
      ['text', 'trim'],
    ];
  }
  
  public function myRule ($attr) 
  {
    if ( !in_array($this->attr, ['Ivan', 'Petr'])) 
    {
      $this->addError($attr, 'Имя должно быть "Petr" или "Ivan"');
    }
  }

Constant error even when you type Ivan or Petr .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ilya, 2018-11-04
@khodos_dmitry

if (!in_array($this->$attr, ['Ivan', 'Petr'])) {
  //
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question