Yii Framework Forum: Throwing exception sends header info - Yii Framework Forum

Jump to content

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

Throwing exception sends header info Rate Topic: -----

#1 User is offline   rtlm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 02-February 14

Posted 13 January 2015 - 11:27 PM

Hi all,
forgive my possible ignorance here but can someone please tell me why throwing an Exception in Yii sends header information?

The following code fails to redirect:

try
{
    throw new Exception("New Exception");
} catch (Exception $ex) {
    Yii::app()->request->redirect("www.google.com");
}


any help appreciated.

This post has been edited by Keith: 14 January 2015 - 04:42 AM
Reason for edit: Fixed code tags.

0

#2 User is offline   alirz23 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,211
  • Joined: 08-August 12
  • Location:Durban, South Africa

Posted 13 January 2015 - 11:38 PM

help yourself


http://stackoverflow...ific-controller
0

#3 User is offline   rtlm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 02-February 14

Posted 13 January 2015 - 11:47 PM

View Postalirz23, on 13 January 2015 - 11:38 PM, said:



Thanks for the suggestion however this does not seem to work for me as my code is running from a static context, and I do not want the controller to catch the exception. I would like the static function which throws the exception to catch it without sending header information (if that's possible)
0

#4 User is offline   Keith 

  • Elite Member
  • Yii
  • Group: Moderators
  • Posts: 1,707
  • Joined: 04-March 10
  • Location:UK

Posted 14 January 2015 - 04:44 AM

I think you just need to fix the URL to include the protocol:

Yii::app()->request->redirect("http://www.google.com");

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