如何在Smfony 2中Doctrine的findBy方法返回的查询结果集中进行迭代



我想替换结果集列的一些字符。我调用以下命令进行DB查询并获得结果:

   $applicant = $em2->getRepository('TestBundle:Person')->findByApplicantName($searchText);

这返回了存储库类的结果集,我可以将变量发送到Twig模板中,通过分页器以这种方式显示结果:

    {% for applicant in pagination %}
    <tr>
    <td>
    {{ applicant.person_address }}
    </td>
    </tr>
    {% endfor %}

在将返回的查询结果交给Twig模板之前,我如何在控制器中对其进行迭代?我创建了以下函数,但我不知道如何到达返回结果集的单个列,并再次将其替换为自己:

foreach ($applicant as $a) {
// $a->person_address ?? it is also ok to replace chars in all columns
$a = str_replace("ü", "ü", $a);
}
$a->getPerson_address(); // Retrieves the address, might want to rethink some of your names

最新更新