这是我的 Controller :
/**
* Finds and displays a Formacion entity.
*
* @Route("/{id}/show", name="curso_show")
* @Template()
*/
public function showAction($id)
{
$em = $this->getDoctrine()->getEntityManager();
$curso = $em->getRepository('GitekUdaBundle:Curso')->find($id);
if (!$curso) {
throw $this->createNotFoundException('Unable to find Curso entity.');
}
$deleteForm = $this->createDeleteForm($id);
// Detalle Formación
$detcurso = new Detcurso();
$formdetcurso = $this->createForm(new DetcursoType(), $detcurso);
return array(
'curso' => $curso,
'delete_form' => $deleteForm->createView(),
'detcurso' => $detcurso,
'formdetcurso' => $formdetcurso,
);
}
在我的开发环境中,工作正常(Mac),但是当我进入生产环境(CentOS服务器)时,
The controller must return a response (Array(curso => Object(Gitek\UdaBundle\Entity\Curso), delete_form => Object(Symfony\Component\Form\FormView), detcurso => Object(Gitek\UdaBundle\Entity\Detcurso), formdetcurso => Object(Symfony\Component\Form\Form)) given).
500内部服务器错误-LogicException
有什么线索吗?
最佳答案
Symfony2期望从 Controller Action 中返回Response对象。我猜您可能想要以下内容:
return $this->render(
"YourBundlePath:Something:template.html.twig",
array(
'curso' => $curso,
'delete_form' => $deleteForm->createView(),
'detcurso' => $detcurso,
'formdetcurso' => $formdetcurso,
)
);
$this->render()
方法将呈现一个提供的模板名称,并在上面的示例中,将该模板传递给您的参数数组。它将生成的内容包装在Response对象中,这正是Symfony2所期望的。您也可以直接返回新的Response对象,例如,如果需要,返回
return new Response('Hello, world')
。有关更多详细信息,请参见the documentation。
关于symfony - Controller 必须返回响应,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/9063103/