我如何在 slim 框架中从控制器重定向到树枝视图?
How I redirect from controller to twig view in slim framework?
如何从控制器重定向到 slim 中的视图?
class ServiceController{
$app = new \Slim\App;
$mw = function ($request, $response, $next) {
$response->withHeader('/twig/html/home.twig');
return $response;
};
$app->run();
}
你可以看看 Documentation (Slim 3) 来渲染模板,在视图对象上有 render
方法。
修身 3
$app->get('/Home', function ($request, $response, $args) {
return $this->view->render($response, '/twig/html/home.twig');
});
苗条 2 (Documentation for Slim 2)
$app->get('/Home', function () use ($app) {
$app->render('/twig/html/home.twig');
});
如果有人正在寻找实际的重定向(而不是渲染视图),就像我发现这个问题时一样,您可以在响应对象上使用 ->withRedirect('url/goes/here')
方法,如下所示:
$app->post('/login', function ($request, $response) {
return $response->withRedirect('/home');
});
如何从控制器重定向到 slim 中的视图?
class ServiceController{
$app = new \Slim\App;
$mw = function ($request, $response, $next) {
$response->withHeader('/twig/html/home.twig');
return $response;
};
$app->run();
}
你可以看看 Documentation (Slim 3) 来渲染模板,在视图对象上有 render
方法。
修身 3
$app->get('/Home', function ($request, $response, $args) {
return $this->view->render($response, '/twig/html/home.twig');
});
苗条 2 (Documentation for Slim 2)
$app->get('/Home', function () use ($app) {
$app->render('/twig/html/home.twig');
});
如果有人正在寻找实际的重定向(而不是渲染视图),就像我发现这个问题时一样,您可以在响应对象上使用 ->withRedirect('url/goes/here')
方法,如下所示:
$app->post('/login', function ($request, $response) {
return $response->withRedirect('/home');
});