In any language, event handling begins with the declaration “when this event occurs with this thing, call this function.” You can construct your events in Yii, but models have their own set of predefined events to keep an eye on before a model is stored, after a model is saved before a model is verified, and so on (the available events will depend upon the model type). Yes, each of the aforementioned approaches corresponds to an event that Yii will keep an eye on with your models.
When anything that happens in one instance of model A should also elicit a reaction in another instance of model B, you’ll want to use events. In time, you’ll see examples of this. However, keeping an eye out for occurrences can be a useful way to take a few extra steps within a single model.
Yii2 events: can cause a preset piece of code to be executed at a specific moment in time. Events aren’t only a method to decouple code; they’re also a way to create business processes. Events are abundant in today’s software. For example, you might post a Weibo, which will cause those who follow you to view your new content as a result of an event.