我有这个用于插入数据的脚本:
echo "Update ";
$department = new Department();
$department->setNamedepartment($data ['nameDepartment']);
$department->setCodedepartment($data ['codeDepartment']);
$department->setIdfkgeographicalarea($data ['idFkGeographicalArea']);
$entityManager->persist($department);
$entityManager->flush();
如何通过此次调用更新$department
实体:update($data,$id)
?
答案 0 :(得分:0)
function update ($data, $id) use ($entityManager) {
$departament = $entityManager->find('Your\EntityNamespace\Departament', $id);
$department->setNamedepartment($data['nameDepartment']);
$department->setCodedepartment($data['codeDepartment']);
$department->setIdfkgeographicalarea($data['idFkGeographicalArea']);
$entityManager->flush();
}