A Question About Events

This is my scenario:

I want a javascript notify system.

refer to Yii2 docs I can write it as a global event(when something happened a global event will be raise)

Is the Controller right place to trig an event?

for example




public function actionTest()

	{

                if (Yii::$app->session->hasFlash('success'))

                        Yii::$app->trigger($eventNotify);

                //do something

		return $this->render('test');

	}



Where can I attach handler to this event




Yii::$app->on($eventNotify, $handler);



Anywhere before raising an event.

Sounds like you are mixing up something here. Javascript runs on the browser while PHP/Yii runs on the server, you can not use Yii events in Javascript.

Yes, I know it.

my point was global event, maybe bad example:D

where is better place for a global event?

If you want truly global handler that should trigger no matter which controller or module is executed you need to attach it before routing started. So index.php, config file.