Сomprehensive Event Examples

I want to resolve Events feature in Yii. But there are not enough examples how to use events. I don’t understand where I can attach a method to event and how to do it.

Please, explicitly explain me how to realise certain following things. 

1) Via event feature it is needed to print html comment "<!-- this text is made by event system of yii -->" before doctype of any page of project. Please give me php code and where I have to place that code (what file? or what model maybe?).

2) Via events feature it is needed to stop execution of project (maybe using die() function) if user request certain controller ('forbiddenController' for example). How to do it? And first off where place php code? i think it is not correct to attach a method to an event in some controller.

So it was my two questions.

If you give me examples how to do it and give me explicit php code and explicit files where this code must be I and many other people will feel appreciation to you.