我有一条路线,我想在其中实现重定向。 根看起来像这样:
$app->get('/registration/validate', function (ServerRequestInterface $request, ResponseInterface $response, $args) {
try {
$user = new \Riecken\PBS\controller\UserController();
$result = $user->validateRegistration($request);
$response = $response->withJson($result);
$response = $response->withStatus(200);
return $response;
}catch(Exception $e) {
$response->getBody()->write($e->getMessage());
return $response->withStatus($e->getCode());
}
});
例如,为了测试它,我想将其重定向到Google。
答案 0 :(得分:0)
在苗条的情况下,redirect()
助手用于将请求重定向到另一个URL。您可以将其用作:
$app->response->redirect('url-here');
有关更多信息,visit here。