App()->End() Vs. Simple Return


I have this controller that handles AJAX notifications from client side.

In a sample action method of it, I process the request and output a simple JSON encoded message according to the request details.

Now, when the output has finished, I’d like the code execution to stop. I have two relevant options:

[list=1][][font="Courier New"]return;[/font][][font="Courier New"]Yii::app()->end();[/font][/list]

Now, is there any difference between the two?

What would you recommend, if there’s any meaningful bias toward one option?

(There are several similar threads out there but none is precise as this in either the question or the replies so I’m phrasing it here).


there is no difference between using both options in action body. In both cases request will end and proper handlers for endRequest will be called.

Yii::app()->end() should be used in code outside action body (event handlers, behaviors, widgets, etc), which must finish request but cannot prevent execution of rest of the action body. In such case Yii::app()->end() should be used instead of plain exit(), because Yii::app()->end() closes request gently and also calls ending handlers.

Gotcha. Thanks.