简体   繁体   中英

How to iterate in query result set returned by findBy method of Doctrine in Smfony 2

I want to replace some chars of a column of result set. I'm calling following to make the DB query and get the results:

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

This return the result set from repository class, and I'm able to send the variable into Twig template to show the result via paginator in this way:

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

How can I iterate in the returned query result in the controller before handing it to Twig template? I created following function, but I don't know how to reach individual column of the returned result set and replace it with itself again:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM