TWIG例外“...... EntityCategoryProxy无法转换为...”

时间:2012-03-29 13:25:59

标签: templates exception symfony doctrine-orm twig

当我想在我的TWIG模板中进行这样的循环时,我得到了这个异常“... EntityCategoryProxy无法转换为...”

{% for category in categories %}     
{{category.name}}
     {% for fund in funds %}
        {% if fund.category == category.id %} <<<<<<< EXCEPTION LINE
            {{fund.fundName}}
        {% endif %}
    {% endfor %}
{% endfor %}

工作类别检索(在接受ANSWER变更后)

    $repository2 = $this->getDoctrine()
        ->getRepository('ToolsTFIBundle:Category');
    $query2 = $repository2->createQueryBuilder('c')
        ->orderBy('c.name','ASC')
        ->getQuery();
    $categoryList = $query2->getResult();

还有工作类别检索(在接受ANSWER变更后)

    $em = $this->getDoctrine();
    $categoryList = $em->getRepository( 'ToolsTFIBundle:Category' )
                                    ->findAll();

“fund.category”是通过Doctrine2 ORM映射到“category.id”的外键。有没有选择让这个循环有效并且有效?

1 个答案:

答案 0 :(得分:3)

fund.category与category.id无法比较,因为fund.category是一个实体。

使用fund.category.id == category.id

相关问题