问题描述:

I am using doctrine 2 and my entity has variables set like:

 /**

* @ORM\Column(type="string")

*/

protected $phone_number;

/**

* @ORM\Column(type="string")

*/

protected $e_mail;

Now i want to fill this variables from array using Hydrator like this:

public function fromArray($values)

{

$hydrator = new \Hydrator\ClassMethodsHydrator();

$hydrator->hydrate($values, $this);

}

But after using this function i get error becuase Hydrator tries to call setphoneNumber() instead of setPhone_number() ...

Can you help me how to achieve my goal instead of changing underscores to camelCase?

Thank you

网友答案:

Try:

 /**
 * @ORM\Column(type="string", name="phone_number")
 */
protected $phoneNumber;

Doctrine would rename your phoneNumber into phone_number anyway when creating your database schema, but by using the name attribute in \Column or \Table Definition you can make sure your name is used.

So in your database table column it's: phone_number

Your entity attribute is called: phoneNumber

So this will usually end up in setPhoneNumber for your setters which is fine.

相关阅读:
Top