How to use event in Yii2

Hi Everyone,

I have been trying to implement event reading this doc .

But unfortuantely I do not understand how use event. I have created a class in components folder as:

namespace app\components;

use yii\base\Component;

use yii\base\Event;

use yii\web\View;

class Foo extends Component{

    const EVENT_HELLO = 'hello';

    public function bar()





I do not understand where I should write the code of yii\base\Component::on() method. Shall I write yii\base\Component::on() method in controller or model. And how to acheve the output of events. Can you give me an example as I can understand the events quickly.

Thanks in advance

see events concepts


I think it is exactly the same Documentation that @StreetCoder speaks about and does not understand too.

I agree with him. Event Should be easy to understand and Yii makes a spagheti explanation and implementation

We must more documentation on this