CJuiDialog page redirect

I am trying to implement a password reset page. After the password is reset i want it to display a dialog saying the email was sent then redirect the page to the login screen the the dialog is closed.

Here is what have for the dialog and redirect:


$this->beginWidget('zii.widgets.jui.CJuiDialog', array(

						'id'=>'mydialog',

						'options'=>array(

						'title'=>'Email Notification',

						'autoOpen'=>true,

						),

					));

					

					echo "Email has been sent!";

					

					$this->endWidget('zii.widgets.jui.CJuiDialog');

					

 					$this->redirect(Yii::app()->createUrl('site/login'));

When the user hits submit to start the password reset function it displays this error page:

Cannot modify header information - headers already sent by (output started at /Library/WebServer/Documents/yii/framework/zii/widgets/jui/CJuiDialog.php:73)

Does anyone know how to fix this? also is there a way to add an ok button on the dialog so when they click ok then it redirects to the login screen?

Thanks

the CController::redirect() use header() function

you can use javascript to redirect

like this





$("form").submit(function() {

   //open the dialog

   $("#mydialog").dialog("open");

   //redirect

   window.location = XXX;

   //$.ajax()

   return false;

});




I just debugged a similar problem.

It turns out that when calling the widget directly from the controller, its output does not get captured and directly goes to the output stream.

So the solution is to put it in a view and render the view (this will capture the output so the header statements will take effect before the "print" actually goes to the output stream.