Yii Framework Forum: App()->End() Vs. Simple Return - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

App()->End() Vs. Simple Return to end or to return? that is the question Rate Topic: -----

#1 User is offline   Boaz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 356
  • Joined: 23-January 11

Posted 09 May 2013 - 03:21 AM

Hi,

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:
  • return;
  • Yii::app()->end();

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).

Thanks!
Therapeutic PHP sessions My LinkedIn Profile
1

#2 User is offline   redguy 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 771
  • Joined: 02-July 10
  • Location:Central Poland

Posted 09 May 2013 - 06:31 AM

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.
red
2

#3 User is offline   Boaz 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 356
  • Joined: 23-January 11

Posted 09 May 2013 - 06:32 AM

Gotcha. Thanks.
Therapeutic PHP sessions My LinkedIn Profile
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users