Answer the question
In order to leave comments, you need to log in
Why might redirect not work in Slim 3.0?
Hello.
I had such a problem - redirect does not work for me.
routes.php
$app->get('/','HomeController:index')->setName('home');
$app->get('/',function($req,$res){ // Не работает
return $res->withHeader('Location', '/auth/signup');
});
public function postSignUp($req, $res) {
return $res->withRedirect($this->router->pathFor('home'));//не работает
//return $res->withStatus(302)->withHeader('Location', '/'); //тоже не работает
}
require __DIR__.'/../vendor/autoload.php';
$app = new \Slim\App();
$app->get('/', function ($request, $response, $args) {
return $response->withHeader('Location', '/auth/signup');// Не работает
});
$app->get('/auth/signup', function ($request, $response, $args) {
return 'Hello';
});
$app -> run();
{
"require": {
"predis/predis": "^1.1",
"slim/twig-view": "^2.1",
"respect/validation": "^1.1",
"slim/slim": "^3.0"
},
"autoload": {
"psr-4": {
"App\\":"app"
}
}
}
Answer the question
In order to leave comments, you need to log in
Check what headers the script generates, it should be something like:
Also, what is your bundle for Nginx + Apache or Ngnix + php-fpm, perhaps the environment variable for the class is not correctly formed:
'environment' => function () {
return new Slim\Http\Environment($_SERVER);
},
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question