We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

redirect problems

Hi, I'm studying the response->redirect; and I encounter 2 strange results:

  1. validation - after redirection, seem like it's going to validate one more time. For example I insert a row that contains unique value, after the redirection it throws me an error. This problem will not occur for forward.
  2. flash session message - similar to validation, a flash message will output twice, and doesn't happen when using forward.

Have any of you encounter this problem?


update:

The strange thing is the same code (haven't change anything, no return) magically produce different result:

  1. validation didn't work yesterday works today.
  2. flash session message still output twice even with return.

they're the simplest code.

    public function testAction(){
        $systemUser           = new SystemUsers();
        $systemUser->username = 'un1'; // this column is unique
        if(!$systemUser->save()){
            foreach($systemUser->getMessages() as $message){
                $this->flash->error((string) $message);
            }
            $this->view->disable();
            $this->response->redirect('test/fail');
            return;
        }else{
            return $this->forward('test/success');
        }
    }

note: apparently the same action (testAction) is executed twice (it happens that it executed four times).


related stackoverflow

Hi,

can you provide an minimal example app with the code? I just tried it on an really simple app and in this, the validation failed everytime and the flash message were only displayed once.

Thanks, Martin



25.7k

Thanks for your reply Martin. Mine also showed validation fail (message) everytime (yesterday); if

  1. create a row (Phalcon app) -> no problem
  2. delete the row (at phpMyAdmin)
  3. create the same row (Phalcon app) -> row is inserted to database, failure detected and error message shown once
  4. repeat 2. to 3.