开发者

Doctrine2 best way to Populate Entities From Zend Form

What's the bets way to populate an Entity in Doctrine from data that I receive from a user form which is a Zend Form.

Class User {
     private $id, $name, $password;
}

And a form with cor开发者_StackOverflow中文版responding:

<input name="name"> <input name="password">

Is there a nice way to assign data from the form (Zend Form) to the User Entity without hard coding every mutator method?


Yes, you can use Reflection API to set property values in an entity. If you have an array, with keys identical to the entity's property names, it wouldn't be too hard to just iterate over them. Make sure you sanitize your input array first though.

For a complex example, take a look at \Doctrine\ORM\UnitOfWork::createEntity()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜