2016-04-30 5 views
-1

コントローラからスリムに表示するにはどうすればいいですか?あなたがテンプレートをレンダリングするためDocumentation (Slim 3)を見てもよいスリムフレームワークでコントローラからツリービューにリダイレクトする方法は?

class ServiceController{ 

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

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

それを達成しようとしていますか? – jmattheis

+0

私は一般にコントローラからビューをレンダリングしたい – vaak

答えて

1

は、ビューオブジェクトのrender -methodあります。

スリム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'); 
}); 
0

私はこの質問を見つけたとき、私はあったように誰もが(レンダリングビューではなく)実際のリダイレクトを探している場合応答オブジェクトに対して->withRedirect('url/goes/here')メソッドを使用することができます。

$app->post('/login', function ($request, $response) { 
    return $response->withRedirect('/home'); 
}); 
関連する問題