开发者

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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜