Redirect page with variable

Im using slim 3.
How can I redirect a page using the
{{route(‘accmember’,{_userid:admuserid})}}

I tried this
return $response->withRedirect(‘memberlist/’.$userid);

Route
$this->get(‘/accmember[/{_memberid}[/{_userid}]]’, App\Controllers\UserGroupController::class . ‘:accmember’)->setName(‘accmember’);

It does work, is it the right way of coding it. I would like to use route(‘accmember’,{_userid:admuserid})

return $response->withStatus(200)->withHeader(‘Location’, ‘/memberlist/’.$userid);

Please any advice

You can please add more details, for example, what template engine plugin/extension is this?

Im using Slim 3 with Twig.

This is return from slim controller with a variable $userid, that needs to be redirected to memberlist with a parameter
return $response->withStatus(200)->withHeader(‘Location’, ‘/memberlist/’.$userid);

example from href tag in twig.
<a href=“{{route(‘memberlist’,{_userid:admuserid})}}”

Route in slim 3
$this->get(‘/memberlist[/{_userid}]’, App\Controllers\UserGroupController::class . ‘:memberlist’)->setName(‘memberlist’);

return $response->withStatus(301)
            ->withHeader('Location', $path);

You need to return a redirect status code such as 301 or 302 rather than the 200 you have there.

See: 300 Multiple Choices - HTTP | MDN for some more info

1 Like