D
D
des1roer2017-09-04 09:46:24
Yii
des1roer, 2017-09-04 09:46:24

Yii2 validator on change?

But how can I make a validator to prevent data changes?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
melnikov_m, 2017-09-04
@melnikov_m

Purely theoretically possible.
Either in your validator, or, for example, in beforeSave, check the attribute for a change and if it has changed, add an error.

if($this->isAttributeChanged('attribute')) {
   $this->addError('attribute', "Текст сообщения об ошибке");
}

M
Maxim Timofeev, 2017-09-04
@webinar

the validator validates, compares, and denies under certain conditions. If you just need to disable - then the validator is the last thing to use.
But if you wrote the question in detail, then there would be a chance of a specific answer with an example.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question