Created
September 29, 2015 23:24
-
-
Save galvao/037138322b642ab0b823 to your computer and use it in GitHub Desktop.
Skeleton related code to ask a question about sequences and
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Usual Skeleton code... | |
public function saveCliente(Cliente $cliente) | |
{ | |
$data = array( | |
'nome' => $cliente->nome, | |
'idempresa' => $cliente->idempresa, | |
); | |
$id = (int) $cliente->idcliente; | |
if ($id == 0) { | |
$sequence = new \Zend\Db\TableGateway\Feature\SequenceFeature('idcliente', 'seq_cliente.nextval'); | |
$data['idcliente'] = $sequence->nextSequenceId(); | |
$this->tableGateway->insert($data); | |
} else { | |
if ($this->find($id)) { | |
$this->tableGateway->update($data, array('idcliente' => $id)); | |
} else { | |
throw new \Exception('Cliente não existe'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment