public function save(User $user) { $data = $user->getRawData(); if ($user->getUserId() > 0) { $id = $user->getUserId(); $this->tableGateway->update($data, array('aufri_users_id' => $id)); } else { if (!$this->tableGateway->insert($data)) { throw new \Exception("Could not new row {$id}"); } $id = (int) $this->tableGateway->lastInsertValue; } return $this->getOne(array('aufri_users_id' => $id)); }