在Symfony2控制器中$ response-> send()之后返回什么?

时间:2013-11-14 16:32:16

标签: php symfony return

如果我在控制器中准备响应,请执行以下操作:

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

而不是使用:

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

然后我还没有回复任何东西......在$ response-> send()之后我该怎么做?我应该回归真实吗?

1 个答案:

答案 0 :(得分: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