-1

I'm trying out slim responses object and redirect feature, i have routes and controllers like this :

routes :

    $app->get('/', 'index:index')->setName('index');

in my controller i have this line :

    return $response->withRedirect($this->router->pathFor('index'));

index function in index class :

public function index($request, $response)
{
    return $this->view->render($response, 'index.html', $this->data);
}

its working, but it gives a HTML document response instead of redirecting me, is this correct behaviour ? if so, how do i redirect to that route ?

jsn alf
  • 43
  • 2
  • 10

1 Answers1

0

Change your code like this:

$uri = $request->getUri()->withPath($this->router->pathFor('index'));
return $response->withRedirect((string)$uri);

You may need to pass $this->router to the controller’s constructor.

Himanshu Upadhyay
  • 6,558
  • 1
  • 20
  • 33