Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redirect()->to() problem with output buffering #769

Closed
gustavojm opened this issue Oct 11, 2017 · 4 comments
Closed

redirect()->to() problem with output buffering #769

gustavojm opened this issue Oct 11, 2017 · 4 comments

Comments

@gustavojm
Copy link
Contributor

I have an AdminController class that all the rest of the controllers will extend.
in the constructor of AdminController I check if the user is already logged, otherwise...

redirect()->to('/admin/user/login');

but it doesn't get redirected, even though I see the 'Location;' header sent to the browser correctly.
Seems to be a problem with the output buffering

For it to work I should do

redirect()->to('/admin/user/login');
ob_end_flush();

should we make the redirect()->to() method call ob_end_flush()?

Thanks in advance!

@lonnieezell
Copy link
Member

Well, it's designed to be returned not just ran, so return redirect()->to(...). However, I didn't think of testing it within a constructor so not 100% sure if it will work correctly in that situation. However, I think filters might be just what you're looking for.

@gustavojm
Copy link
Contributor Author

Initially I was using return redirect()->to('/admin/user/login'); but it didn't redirect. It returned to the constructor of the child class and kept executing the code of the controller.
That's why I had to remove the return statement, to be able to execute the ob_end_flush() after that

@lonnieezell
Copy link
Member

Gotcha, and that's what I was afraid of. So, that's something I'll take a look into in the near future.

Filters, however, were designed for exactly what you're trying to do.

@demortx
Copy link

demortx commented Oct 14, 2017

Debug off -> work redirect()->to(...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants