我如何在苗条框架中从控制器重定向到树枝视图?

时间:2016-04-30 10:20:38

标签: twig slim

我如何从控制器重定向到苗条?

class ServiceController{

    $app = new \Slim\App;
    $mw = function ($request, $response, $next) {

                    $response->withHeader('/twig/html/home.twig');
                    return $response;
    };
    $app->run();
}

2 个答案:

答案 0 :(得分:2)

您可以查看Documentation (Slim 3)以呈现模板,视图对象上有render - 方法。

超薄3

$app->get('/Home', function ($request, $response, $args) {
    return $this->view->render($response, '/twig/html/home.twig');
});

Slim 2(Documentation for Slim 2

$app->get('/Home', function () use ($app) {
    $app->render('/twig/html/home.twig');
});

答案 1 :(得分:0)

如果有人在寻找实际的重定向(而不是渲染视图),就像我找到这个问题时那样,你可以在响应对象上使用->withRedirect('url/goes/here')方法,如下所示:

$app->post('/login', function ($request, $response) {
    return $response->withRedirect('/home');
});