对Table Post进行 SQL 查询后,我希望将 $result 数组合并到 Doctrine 对象中。现在,为了做到这一点,我对每个字段使用 set 命令,如下所示:
$post = new post(); $post->setCategory($result['category']); $post->setName($result['name']); $post->setRating($result['rating']);
我的问题是有没有更好的方法来做到这一点,例如迭代所有表字段?谢谢。
最佳答案
您可以使用fromArray()
:
$post = new Post();
$post->fromArray($results);
关于mysql - 交响乐/Doctrine : How to iterate through table fields for hydration?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4942695/