E
E
Eugene Vdovenko2015-12-15 13:56:44
Zend Framework
Eugene Vdovenko, 2015-12-15 13:56:44

Why doesn't redirect work in Zend Framework 2?

The controller method has a manageAction() method.
I call the fillForm() method in it.
The fillForm() method has a try...catch block, in the catch section of which I add an error message and a redirect.

$this->flashMessenger()->addErrorMessage("Ошибка при работе с API v1.5.");
return $this->redirect()->toRoute('home');

This is according to the documentation. And it doesn't work. Those. handles the ViewModel of the manageAction() action, not indexAction() as specified in the "home" route. However, if you write like this:
$this->redirect()->toRoute('home');
$this->flashMessenger()->addErrorMessage("Ошибка при работе с API v1.5.");

everything works as it should. And the most interesting thing is that if you directly call manageAction()
$this->flashMessenger()->addErrorMessage("Ошибка при работе с API v1.5.");
return $this->redirect()->toRoute('home');

everything works too.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Arutyunov, 2015-12-15
@arutyunov

Are you sure the catch is working?
And that in $this you have a redirect() method?
Check with a debugger what works for you and what doesn't.

A
Andrey Mokhov, 2015-12-15
@mokhovcom

Obviously, you return Responce in the fillForm method, but who will return in manageAction?

public function manageAction()
{
    // ...
    $ret = $this->fillForm();
    if ($ret instanceof Response) {
        return $ret;
    }
    // ...
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question