How to save Doctrine2 Entity if all fields are private? Is there some kind of mechanism to do that?
How can I save this:
/**
* @Entity
*/
class SomeEntity
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column */
private $title;
}
How to change title
for example? Maybe it's possible via EntityManager?
PS: Thanks in advance
class SomeEntity
{
/** @Id @Column(type="integer") @GeneratedValue */
private $id;
/** @Column */
private $title;
public function setTitle($title){
$this->title = $title;
}
}
Use like this:
$entity = new SomeEntity();
$entity->setTitle('title');
$em->persist($entity); //$em is an instance of EntityManager
$em->flush();
This is a proper way emphasized in the manual.
public function __get($property)
{
return $this->$property;
}
public function __set($property,$value)
{
$this->$property = $value;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With