1

From view() of a single page controller I can redirect like following:

use \Concrete\Core\Http\ResponseFactory;
return ResponseFactory::redirect($this->getRequest()->getPathInfo());

From the view() method of a block controller the redirection with the above snippet does not work. I also tried to return the value of the AbstractController::buildRedirect() with no success.

Therefor my question is: What kind of support from c5 does exist to redierct from view() of a block controller?

1stthomas
  • 731
  • 2
  • 15
  • 22
  • The way the redirection works on `view()` of a block controller is: `ResponseFactory::redirect($this->getRequest()->getPathInfo())->send();`. But then a new question arises: why do page and block controllers handle it different? Shouldn't it be handled the same? – 1stthomas Sep 29 '21 at 08:43

1 Answers1

0

A possibility is, as I mentioned in the comment, to send the response. But then the script has to be exited to avoid rendering the view. The related snippet would be as following:

$this->app->make(ResponseFactoryInterface::class)
        ->redirect($this->getRequest()->getPathInfo())
        ->send();
exit;
1stthomas
  • 731
  • 2
  • 15
  • 22
  • Open questions: Best practice? Is the different handling (page-/block controller) a bug or as intended? – 1stthomas Sep 29 '21 at 09:16