When do you need to execute end()?

end() is the method of CApplication. According to the Guide, end() will "Terminates the application."

My question is when and under what circumstance, you need to use end() to stop the application?

I am a beginner, even after reading Yii Guide and tutorials. The Yii book, I can only assimilate 40% of the content. What do suggest is the best way to learn to use each class?

Well you could use Yii::app()->end() where you need to. For example in a controller where you check the role of a specific user like this:


if( !Yii::app()->user->checkAccess('clientAdmin')) {



Also using that code will mean that your application will end properly (which is different to die;) so the logs file for example will be still written.

if the user doesn’t have access right to this action, why not direct him to the login page again? Instead, why we want to end the application?

I use end() mostly for debugging & test purposes :D die() is not what I need, because web logs won’t be displayed. Also end() is useful for ajax requests, when you need only to echo something and then terminate the application.

Thanks a lot! I’ll remember this when next time I see end().