Alex Rivera | Logout

Can doctrine2 hydrate a new entity from an array?

Asked 2011-06-22T00:58:46.623
23

I think the title asks it all. Very simple, I have an entity:

class User {
    private $id;
    private $name;
    private $username;
}

with all the appropriate setters and getter. I have an array:

array( 'name' => 'joe', 'username' => 'shmoe' );

and I want to be able to do something like this:

Some\Unknown\Doctrine\Object::hydrateFromArray($array);

Obviously creating a function to hydrate it an object would be easy enough, but surely doctrine must have something build in to accomplish this?

Edit
Report

1 Answer

20

Figured it out. Given a repository:

//for odm
$repo->getDocumentManager()->getHydratorFactory()->hydrate($entity, $array);

I don't know if the same can be done for ORM, but I'm currently using ODM.

answered 2011-06-22T12:24:01.820

Your Answer