小编use*_*729的帖子

Symfony2和Twig:显示所有字段和键

我有Symfony2和Twig的问题:我不知道如何显示动态加载的实体的所有字段.这是我的代码(什么都没显示!!)

控制器:

public function detailAction($id)
{
    $em = $this->container->get('doctrine')->getEntityManager();

    $node = 'testEntity'
    $Attributes = $em->getRepository('TestBetaBundle:'.$node)->findOneById($id);

    return $this->container->get('templating')->renderResponse('TestBetaBundle:test:detail.html.twig', 
    array(
    'attributes' => $Attributes
    ));

}
Run Code Online (Sandbox Code Playgroud)

detail.html.twig:

    {% for key in attributes %} 
        <p>{{ value }} : {{ key }}</p>
    {% endfor %}
Run Code Online (Sandbox Code Playgroud)

entity symfony twig

6
推荐指数
2
解决办法
1万
查看次数

标签 统计

entity ×1

symfony ×1

twig ×1