我该怎么做更新表原则

时间:2016-03-20 11:15:05

标签: php doctrine-orm zend-framework2

我有这个用于插入数据的脚本:

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)

1 个答案:

答案 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();
}