0

I'm using php templates instead of Twig templates in symfony2.3.

Inside this I need to write a doctrine code in PHP template.
So I'm trying to create object for entity manager using following code

$em = $this->getDoctrine()->getEntityManager();

$query = $em->createQuery("SELECT t FROM MyBundle:$TableName t $Condition ");

$result = $query->getArrayResult();

But its not working.

4

1 回答 1

0

您不能在模板内执行此操作。相反,在控制器中设计您的逻辑并在模板中渲染控制器:

<?php echo $view['actions']->render(
new ControllerReference(
    'MyBundle:MyController:myMethod'
))
?>

在方法中,编写您的代码。

于 2013-10-23T10:42:23.437 回答