The controller must return a response

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,
        );
}

It works fine in my development environment (Mac), but when I go to my production environment (CentOS server), I get

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?

+5
source share
7 answers

Symfony2 expects a Response object to be returned from a controller action. I assume that 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 method $this->render()will display the provided template name, and in the above example, pass the template to your array of parameters. It will wrap this generated content in a Response object, which is what Symfony2 expects.

You can also return a new Response object directly, for example return new Response('Hello, world'), if necessary.

. .

+18

, , , , .

, , , , , , , @template , symfony crud.

, , FosRestBundle, , , config.yml:

#The view_annotations flag must be false to work with FOSRestBundle
sensio_framework_extra:
    view:
        annotations: false   

, @template. , , .

, , , . ^ _ ^!

, -

+4

sensio_framework_extra:
   view:
      annotations: true
+3

Kox Inori , $this- > render , .

2 :

  • . ?
  • . ? CentOs , Mac OS Windows . template template .
  • . bin vendors/update ?
+1

, symfony2 @Template ( $this- > render()). , , , .

symfony: php app/console cache: clear --no-warmup --env = prod

0

:

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
0

All Articles