Controller Redirect Dont Work In Some Controllers

It works in xammp ,ubuntu lamp and windows shared host plan.

Change plan to linux shared host and $this->redirect stop working in at least 2 controllers.

Debugg ok, code reach redirect but nothing hapens.

possible causes?

Any help?

Personally I would start by looking at the network traffic. Either using a packet sniffer or something like fiddler. See if the redirects are coming through.

The host shouldn’t have any influence on a redirect response being sent.

Try using just a base package, that doesn’t do anything else but redirect, see what that does.

I think it is just a matter of eliminating things at this stage.

thanks for your help.

this is all the code in action.

no redirect at all, and blankscreen


public function actionCreate() {


        $Pagamento = new ReservaPayment();

        $Reserva = new Reserva();

        $model = new Preco('create');

       // $this->actionValida();

       // $uid = Yii::app()->user->name == ("admin") ? " >=1" : "=" . Yii::app()->user->id;

        $cod_casa = Yii::app()->getRequest()->getQuery('cod_casa');


       // $this->actionCalendar($cod_casa, 0);

        // $this->performAjaxValidation($model);


      /*  if (isset($_POST['Preco'])) {


            $model->attributes = $_POST['Preco'];


            if ($model->save()) {


                Yii::app()->user->setFlash('success', 'Ok com disponibilidade!', true);

                $id = Yii::app()->db->lastInsertID;


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


                    $Reserva->attributes = $_POST['Reserva'];

                    $Reserva->valor=$_POST['Preco']['preco'];

                    $Reserva->user = $_POST['Reserva']['user'];

                    $Reserva->idpreco = $id;

                    $Reserva->reserva_state = $_POST['Reserva']['reserva_state'];


                    if ($Reserva->save()) {


                        $idreserva = Yii::app()->db->lastInsertID;

                       

                        $Reserva->checkOutdated($id);


                        $Reserva->sendMails($idreserva,NULL);

     

                    } else {

                        Yii::app()->user->setFlash('error', 'Erro com Reserva!', true);

                    }

                }

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




                    $Pagamento->attributes = $_POST['ReservaPayment'];

                    if (isset($idreserva)) {

                        $Pagamento->idreserva = $idreserva;

                    }

                    $Pagamento->idpreco = $id;


                    if ($Pagamento->save()) {

                        Yii::app()->user->setFlash('success', 'Ok com Periodo Reserva Pagamento !', true);

                    } else {

                        Yii::app()->user->setFlash('error', 'Pagamento não introduzido !', true);

                    }

                }

            }

        } else {


            Yii::app()->user->setFlash('error', 'Erro com Periodo Reserva e pagamento! Confira as datas em conflito', true);

        }

        if (isset($idreserva)) {

           

            $this->redirect( array('reserva/view/','id' => $idreserva, 'fromP' => '1',));

        } else {

            $this->redirect( array('casa/update/','id' => $cod_casa, 'fromP' => '1',));

        }*/

         $this->redirect( array('casa/update/','id' => $cod_casa, 'fromP' => '1',));

    }

What happens if you just do this…


public function actionCreate() {


         $this->redirect( array('casa/update/'));

    }

Hi Led,

I would also like to suggest you to check $cod_casa query parameter.


public function actionCreate() {

         $cod_casa = Yii::app()->getRequest()->getQuery('cod_casa', "empty");

         Yii::trace("cod_casa = $cod_casa");

         $this->redirect( array('casa/update/','id' => $cod_casa, 'fromP' => '1',));

    }



My guess is that actionCreate fails to get a valid $cod_casa in some situation, and createUrl() fails because of that.

@ mboz62

yes it works

[quote=“softark, post:5, topic:58167”]

Hi Led,

I would also like to suggest you to check $cod_casa query parameter.


public function actionCreate() {

         $cod_casa = Yii::app()->getRequest()->getQuery('cod_casa', "empty");

         Yii::trace("cod_casa = $cod_casa");

         $this->redirect( array('casa/update/','id' => $cod_casa, 'fromP' => '1',));

    }



My guess is that actionCreate fails to get a valid $cod_casa in some situation, and createUrl() fails because of that.

[/quote

@softark

it works with $cod_casa = Yii::app()->getRequest()->getQuery(‘cod_casa’, “empty”); and full action code above, but no save no flash messages.

This is very starnge

IMO this has to do with php config someway.

[quote=“Led, post:7, topic:58167”]

[quote=“Led, post:7, topic:58167”]

Hi Led,

I would also like to suggest you to check $cod_casa query parameter.


public function actionCreate() {

         $cod_casa = Yii::app()->getRequest()->getQuery('cod_casa', "empty");

         Yii::trace("cod_casa = $cod_casa");

         $this->redirect( array('casa/update/','id' => $cod_casa, 'fromP' => '1',));

    }



My guess is that actionCreate fails to get a valid $cod_casa in some situation, and createUrl() fails because of that.

[/quote

@softark

it works with $cod_casa = Yii::app()->getRequest()->getQuery(‘cod_casa’, “empty”); and full action code above, but no save no flash messages.

This is very starnge

IMO this has to do with php config someway.

@softark why redirect dont work in other controller that dont get a parameter.

ex:

another controller


 public function actionCreate() {

        if (Yii::app()->user->name == '***@sapo.pt') {

            $model = new Casa('admin');

        } else {

            $model = new Casa('notCertif');

        }

        //Uncomment the following line if AJAX validation is needed

        $this->performAjaxValidation($model);


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

            $model->attributes = $_POST['Casa'];

            if ($model->save()) {

                $id = Yii::app()->db->lastInsertID;


                $fbpost = new FbPost();

                $fbpost->post($id, 'casa');

                $this->redirect(array('update', 'id' => $id));

            }

        }


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

            'model' => $model,

        ));

    }

here the padron is


$id = Yii::app()->db->lastInsertID;

but what intrigues me is it works in other 3 diferent environments. localhost lamp(ubuntu), localhost wammp(windows7) ,shared host windows server.

http://www.casasdapraia.pt/phpinfo.php

I think that problem is not in redirection.

It’s only my guess, but your app stops somewhere else before doing redirection.

I would run the app with full debugging options in the problematic environment and see what’s really happening by looking at the log.

[P.S.]

Another thing comes to my mind is a, well, I call it "favicon.ico problem".

When there’s no favicon.ico in the root, some browser will repeat the same identical request twice. It may explain why you loose the flash message.

"it works in other 3 diferent environments. localhost lamp(ubuntu), localhost wammp(windows7) ,shared host windows server."

change host and use it to another domain

I know. :) But saying that doesn’t help you a bit, because it doesn’t work in your current environment. I understand your frustration, but you have to debug in your current environment.

point me a direction to debug on host ,firephp?

There’s nothing special. Just do as you do in your development phase.

In php.ini

  1. Set error_reporting to E_ALL.

  2. Set display_errors to On.

In /index.php

  1. Set "YII_DEBUG" to true.

And see what’s happening. You may want to check /protected/runtime/application.log. And also you may want to insert some “Yii::trace()” in your code to trace the code execution.

[Note]

I’m in the assumption that your code has a hidden flaw that has not been revealed in other environments. I might be wrong and the cause of the problem might not be in your code.

Sorry, if I’m wrong.

thanks . i’ll see what i can do and give some feedback

index.php:


<?php





// change the following paths if necessary

$yii=dirname(__FILE__).'/framework_latest/yii.php';

$config=dirname(__FILE__).'/protected/config/main.php';


// remove the following lines when in production mode

defined('YII_DEBUG') or define('YII_DEBUG',true);

// specify how many levels of call stack should be shown in each log message

defined('YII_TRACE_LEVEL') or define('YII_TRACE_LEVEL',3);


require_once($yii);

Yii::createWebApplication($config)->run();







?>