V
V
Vlad Osadchyi2020-11-26 19:57:15
Yii
Vlad Osadchyi, 2020-11-26 19:57:15

How to perform an action only after updating a specific attribute?

In Yii2 ActiveRecord in EVENT_AFTER_UPDATE I need to perform a certain action, but only when one particular attribute changes. In addition, I need to know the previous value of this attribute. How can this be done?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kulay, 2020-12-04
@VladOsadchyi

This can be tracked in afterSave. To do this, there is $changedAttributes and the getOldAttribute method.
!$insert && $changedAttributes['name'] !== null && $changedAttributes['name'] !== $this->getOldAttribute('name') - this can be thought of as changing the "name" attribute.
You can also look towards AttributeBehavior.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question