M
M
Maxim Timofeev2016-08-20 14:47:33
Yii
Maxim Timofeev, 2016-08-20 14:47:33

How to trigger an event in yii2?

I have a behavior that loads pictures, is hung up on events: EVENT_BEFORE_INSERT and EVENT_BEFORE_UPDATE

public function events()
  {
    return [
        ActiveRecord::EVENT_BEFORE_INSERT => 'upload',
        ActiveRecord::EVENT_BEFORE_UPDATE => 'upload',
    ];
  }

But if the attributes have not changed, then they do not work. And the $photo attribute just changes inside "upload". Vicious circle. How to overcome?
If you send some other modified attribute along with the picture, it works. But that's not an option.
The fact is that the picture is a public variable, while it got out of the situation by passing another attribute along with it, which in fact does not change but causes events.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nikita, 2016-08-20
@webinar

These behaviors to download at least ... chew, why not see how it was done there or is it better to take it ready-made?
Re:
yii\db\ActiveRecord::markAttributeDirty()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question