Redirect Does Not Work

Redirect does not work, I don’t know why, below is the brief code:




	public function actionUpdate($id)

	{

                Yii::app()->language = 'zh_cn';

        

		$model=$this->loadModel($id);

        

		if(isset($_POST['DYClass'])) {

                    $model->save();

		    $this->redirect(array('schedule')); // it didn't redirect after save

                }


		$this->render('update',array(

			'model'=>$model,

		));

	}



Are you sure that isset($_POST[‘DYClass’]) is true?

If yes, then what exactly happens after submit?

Yes, I am sure that isset($_POST[‘DYClass’]) is true, because I tried replacing the redirect code with just “return”, it will return to a blank page.

After submit, it stayed on the update page, didn’t redirect to any other page and didn’t show any error.

The more weird thing is that if I replace the redirect code with echo and return as below, it didn’t return to a blank page with “ok” text either, just stayed on the update page.




        public function actionUpdate($id)

        {

                Yii::app()->language = 'zh_cn';

        

                $model=$this->loadModel($id);

        

                if(isset($_POST['DYClass'])) {

                    $model->save();

                    echo "ok";

                    return;

                }


                $this->render('update',array(

                        'model'=>$model,

                ));

        }



Niiiiiiice.

Ok, is it just a plain (I mean non-ajax) request?

Can you check what headers are being sent on response? (you can do it for example in google chrome dev console, or firebug)

I used chrome console, wow, how great it is, I never knew that I can use it to debug.

Actually, I am not familiar with ajax. :P

what the error showed in the chrome console when I click the submit button is as below:

[b]Uncaught TypeError: Object #<Object> has no method ‘sendMessage’ Browser.js:2

 Browser.sendToExtension Browser.js:2


 g init.js:2


 (anonymous function) init.js:4

Uncaught ReferenceError: xl_chrome_menu is not defined xl.js:111

 HideXLMenu xl.js:111


 onDocClick[/b]

Are you familiar with these errors?

Thanks. :)

Oh, that’s nothing, seems like some browser extension is broken.

Then how should I debug it? Thanks. :)

You can use console to investigate request/response headers, ajax requests and so on.

But first try to turn off ajax and client validation of your form.

I resolved it. haha ~~

I enabled “validateOnSubmit” in form, but in action, I didn’t add validation code:




            if(isset($_POST['ajax']) && $_POST['ajax']==='dyclass-form'){

                echo CActiveForm::validate($model);

                Yii::app()->end();

            }



Thanks for your help. :)