Symfony/Doctrine: How to iterate through table fields for hydration?
After making a SQL query to Table Post I wish to hydrate the $开发者_JAVA技巧result array to a Doctrine object. Right now in order to do this I use a set command for each field, as below:
$post = new post(); $post->setCategory($result['category']); $post->setName($result['name']); $post->setRating($result['rating']);
My question is is there a better way to do this, such as iterating through all the table fields? Thanks.
You can use fromArray()
:
$post = new Post();
$post->fromArray($results);
精彩评论