This is my 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,
);
}
In my development enviroment works fine (Mac) but when I go to my production enviroment (CentOS server) I´m getting
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 Internal Server Error - LogicException
Any clue?
Looks like anotation @Template
doesn't work for you. Check configuration http://symfony.com/doc/2.0/bundles/SensioFrameworkExtraBundle/annotations/view.html , http://symfony.com/doc/2.0/bundles/SensioFrameworkExtraBundle/index.html
Symfony2 expects a Response object to be returned from a controller action. I'm guessing you probably want something like the following:
return $this->render(
"YourBundlePath:Something:template.html.twig",
array(
'curso' => $curso,
'delete_form' => $deleteForm->createView(),
'detcurso' => $detcurso,
'formdetcurso' => $formdetcurso,
)
);
The $this->render()
method will render a supplied template name, and in the example above, pass the template your array of parameters. It'll wrap this generated content in a Response object, which is what Symfony2 is expecting.
You can also return a new Response object directly, eg return new Response('Hello, world')
if needed.
See the documentation for more details.
Well I had this problem too and this post was the nearest to my problem but didn't solve it, then I want to write here my solution just in case some people had my problem too.
Seems that there is a problem with the template annotation like some people said above, you can workaround the problem using the render function but I think that is not a good solution because the @template annotation tries to do this template managing easier and is used by default in the symfony crud generator.
So, my problem was that I have FosRestBundle installed and I had to disable template annotations when I installed it by adding this lines to the config.yml:
#The view_annotations flag must be false to work with FOSRestBundle
sensio_framework_extra:
view:
annotations: false
You have to remove those lines to get the @template annotation working again. It's strange because I only had this problem after do the last composer update, but not before.
This is the problem of follow the bundle install documentation without understanding what are you doing at all hehe ^_^!
Hope this helps someone
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With