0
我正在使用ZfcBase更新表,当我通过实体并提取原始数据时它获取实体Id(这是主键),但我不想包含id为更新,什么是排除实体id(主键),以便它不会得到sql语句的适当方式?取消设置主键更新ZfcBase
感谢
我正在使用ZfcBase更新表,当我通过实体并提取原始数据时它获取实体Id(这是主键),但我不想包含id为更新,什么是排除实体id(主键),以便它不会得到sql语句的适当方式?取消设置主键更新ZfcBase
感谢
这是我做的,我传递一个简单的阵列,而不是对象。
$entity = array('authorized' => $authorize);
$where = array('id' => $id);
$mapper->update($entity , $where);
这是在ZfcBase AbstractDbMapper映射器
public function update($entity, $where = null, $tableName = null, Hydrator $hydrator = null)
{
$hydrator = $hydrator ?: $this->getHydrator();
if (!$where) {
$where = array('order_id' => $entity->getId());
}
return parent::update($entity, $where, $this->getTableName(), $hydrator);
}
存在是获取呼吁更新
$rowData = $this->entityToArray($entity, $hydrator);
protected function entityToArray($entity, HydratorInterface $hydrator = null)
{
if (is_array($entity)) {
return $entity; // cut down on duplicate code
} elseif (is_object($entity)) {
if (!$hydrator) {
$hydrator = $this->getHydrator();
}
return $hydrator->extract($entity);
}
throw new Exception\InvalidArgumentException('Entity passed to db mapper should be an array or object.');
}
正如你可以看到这个方法的方法可以接受和对象或数组。我刚刚发送了一个普通的数组。