PHP cannot redirect from within a callback
This is strange.
I have a regular event service in my application that listens for triggered events registered with the service. If an administrator is editing a product, for example, and this event is registered, the callback is triggered based on the settings of the registered event.
In my callback, I set up a redirect to the error log just to validate the event.
public function editProduct($data) {
Response::redirect(Url::link('tool/error_log', 'token=' . Session::get('token'), 'SSL'));
}
The callback is being executed because if I var_dump the data argument, I get this:
array (size=1)
'product_id' => string '42' (length=2)
But for some reason, the redirection will fail, no errors or exceptions, nothing.
I also tried it without facades:
public function editProduct($data) {
$this->response->redirect(
$this->url->link('tool/error_log', 'token=' . $this->session->data['token'], 'SSL')
);
}
I also tried to get the redirect back:
public function editProduct($data) {
return $this->response->redirect(
$this->url->link('tool/error_log', 'token=' . $this->session->data['token'], 'SSL')
);
}
Both objects or facades work throughout my application, so I know they are the wrong classes.
Even Whoops works for me and it doesn't throw any errors.
I'm stumped.
source to share