I am using the HttpFoundation component in my project without using the full Symfony2 framework. I try to make a RedirectResponse if some credentials are true and redirect the user (like stated in the documentation), but the return
statement is not working.
I have:
use Symfony\Component\HttpFoundation\RedirectResponse;
$logged = 1;
if ($logged == 1) {
$response = new RedirectResponse('http://google.com/');
return $response;
} else {
die("not logged");
}
Nothing happens when i execute this. But if I do this instead, I am successfully redirected to Google:
if ($logged == 1) {
$response = new RedirectResponse('http://google.com/');
echo $response;
}
Why does this work with echo
but not with return
? I don't want to use echo
in my class libraries.
Any solutions?
Try: $response->send();
instead echo $response;
.