Skip to content

Instantly share code, notes, and snippets.

@galvao
Created September 29, 2015 23:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save galvao/037138322b642ab0b823 to your computer and use it in GitHub Desktop.
Save galvao/037138322b642ab0b823 to your computer and use it in GitHub Desktop.
Skeleton related code to ask a question about sequences and
<?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