【发布时间】:2011-09-23 19:10:36
【问题描述】:
在 $entity 变量中,有一个与 $other_address 相同类型的对象,但所有字段值都被填写。
我想将 $other_address 对象中的所有字段设置为与 $entity 对象具有完全相同的值。
这在少于 N 行中是否可行,其中 N 是我需要设置的字段数?
我尝试了“克隆”关键字,但没有成功。
这是代码。
$other_address = $em->getRepository('PennyHomeBundle:Address')
->findBy(array('user' => $this->get('security.context')->getToken()->getUser()->getId(), 'type' => $check_type));
$other_address = $other_address[0];
//I want to set all values in this object to have values from another object of same type
$other_address->setName($entity->getName());
$other_address->setAddress1($entity->getAddress1());
$other_address->setAddress2($entity->getAddress2());
$other_address->setSuburbTown($entity->getSuburbTown());
$other_address->setCityState($entity->getCityState());
$other_address->setPostZipCode($entity->getPostZipCode());
$other_address->setPhone($entity->getPhone());
$other_address->setType($check_type);
【问题讨论】:
标签: doctrine doctrine-orm symfony