I am currently developing a module for icingaweb 2. I’m facing an issue where I have a view with input fields and a submit button. When pressing the submit button I currently am altering the view to show a success message. But I need the view to change to another view. I basically want to go back one page. How could I achieve this?
our forms already have such a handling in place. Just set the url on the form object and it’s utilized once the submit is finished.
use Icinga\Web\Url;
// Also accepts just the path as string
$url = Url::fromPath('yourmodule/controller/action', ['param' => 'value']);
$form = new YourForm();
$form->setRedirectUrl($url);
If you want to perform a redirect manually, you can do this in two ways:
In the controller:
$this->redirectNow($url);
With the response anywhere else:
use Icinga\Application\Icinga;
Icinga::app()->getResponse()->redirectAndExit($url);