2

次のようにコントローラーで応答を準備すると:

$response = new Response();
$response->setContent($this->render('mytemplate.html.twig');
$response->send();

使用する代わりに:

return $this->return('mytemplate.html.twig');

その後、実際には何も返されませんでした... $response->send() の後で何をすればよいでしょうか? trueを返すだけですか?

4

1 に答える 1

3

応答を返す必要があります

symfony のドキュメントから:

コントローラーの目的は常に同じです。Response オブジェクトを作成して返すことです。

例:

use Symfony\Component\HttpFoundation\Response;

public function helloAction()
{
    return new Response('Hello world!');
}

もう一つの例:

use Symfony\Component\HttpFoundation\Response;

$content = $this->renderView(
    'AcmeHelloBundle:Hello:index.html.twig',
    array('name' => $name)
);

return new Response($content);

ここでそれについて読むことができます: http://symfony.com/doc/current/book/controller.html

于 2013-11-14T16:38:17.187 に答える