I’m not sure what is going on here. I swear I had the redirect working before, but now it isn’t.
Relevant Namespaces:
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
Initialization and container:
$app = new \Slim\App(["settings" => $config]);
// Fetch DI Container
$container = $app->getContainer();
// Register Twig View helper
$container['view'] = function ($c) {
$view = new \Slim\Views\Twig($_SERVER['DOCUMENT_ROOT'].'/Feedback/templates', [
'cache' => false
]);
// Instantiate and add Slim specific extension
$basePath = rtrim(str_ireplace('index.php', '', $c['request']->getUri()->getBasePath()), '/');
$view->addExtension(new Slim\Views\TwigExtension($c['router'], $basePath));
return $view;
};
Here’s the redirect:
$app->get('/test', function (Request $request, Response $response) {
$url = $this->get('router')->pathFor('dashboard');
return $response->withStatus(302)->withHeader('Location', $url);
});
Can someone please help me figure this out.