A
A
Alexander Sharomet2017-02-02 17:08:40
PHP
Alexander Sharomet, 2017-02-02 17:08:40

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');
});

AuthController.php
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();

composer
{
    "require": {
        "predis/predis": "^1.1",
        "slim/twig-view": "^2.1",
        "respect/validation": "^1.1",
        "slim/slim": "^3.0"
    },
  "autoload": {
    	"psr-4": {
    		"App\\":"app"
    	}
    }
}

After registering a user, it should be redirected to the home page, but this does not happen, nothing happens at all. it just executes the postSignUp method and nothing happens.
What could be the problem? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Egor Gruzdev, 2017-02-07
@sharomet

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);
    },

those. pay attention to the REQUEST_URI variable

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question