Search code examples
concrete5concrete5-8.x

Redirect Block Controller view()


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?


Solution

  • 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;