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.

+3


source to share


2 answers


I solved this by posting an exit after the redirect. Apparently the headers for the redirect have been overwritten.



0


source


I am missing the comments, so I hope I agree with this as an answer.



Is it possible that there is some kind of output appearing in front of your title? I believe this can cause a white screen of death.

0


source







All Articles