how to use slim redirect

后端 未结 9 1457
有刺的猬
有刺的猬 2020-12-14 02:45

I have a problem. I am using slim and I have route for my main page:

$app->get(\'/\', function() use ($app) { ... 

In one of my controll

9条回答
  •  青春惊慌失措
    2020-12-14 03:00

    Slim 4:

    $response->withHeader('Location', '/redirect/to');
    

    Or in place of fixed string:

    use Slim\Routing\RouteContext;
    
    $routeParser = RouteContext::fromRequest($request)->getRouteParser();
    $url = $routeParser->urlFor('login');
    
    return $response->withHeader('Location', $url);
    

    Slim Documentation: http://www.slimframework.com/docs/v4/objects/response.html#returning-a-redirect RouteContext: https://discourse.slimframework.com/t/redirect-to-another-route/3582

提交回复
热议问题