Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Fala pessoal,
Estou fazendo um insert com doctrine2, e assim que termino o insert pego o id gerado desse insert e devolvo na minha rota para vizualizar o ultimo registro. Nessa tabela onde insiro esse novo registro, tenho algumas chaves estrangeiras. O que esta acontecendo é o seguinte:
Dou o insert
$em->persist($servico);
$em->flush();
pego o ultimo id gerado do insert
$lastSrv = $servico->getIDSERVICO();
Agora faço um select para ver todos os dados que foram inclusos e mostrar para o usuário
try {
$sdao = $em->getRepository("Application\Model\Servico");
$listaLastServ = $sdao->lastid($lastSrv);
$view->setVariable("resp", "<div class='alert alert-success' role='alert'>"
. "<strong>Novo Serviço Cadastrado com sucesso. </strong> </div>");
} catch (Exception $ex) {
$view->setVariable("resp", "<div class='alert alert-warning' role='alert'>"
. "<strong>Erro no Cadastrado!!! </strong> </div>");
}
}
$view->setVariable("listagem", $listaLastServ);
return $view;
Esse é o meu $sdao
public function lastid($ids)
{
$em = $this->getEntityManager();
return $em->createQuery("SELECT s FROM Application\Model\Servico AS s "
. " WHERE s.IDSERVICO = :sid")
->setParameter("sid", $ids)
->getResult();
}
Nessa tabela ou classe serviço eu tenho as seguintes colunas:
IDSERVICO int(10)
ID_CLI, int(10), NO, MUL, ,
ID_MOT, int(10), NO, MUL, ,
ID_TARIF, int(10), NO, MUL, ,
ID_FORNC, int(10), NO, MUL, ,
DATA_INICIO, date, YES, , ,
DATA_FIM, date, YES, , ,
HORA_INICIO, time, YES, , ,
HORA_FIM, time, YES, , ,
NOME_GUIA, varchar(45), YES, , ,
VOO, varchar(15), YES, , ,
PAX, int(3), YES, , ,
GRUPO, varchar(45), YES, , ,
FILE, varchar(15), YES, , ,
QUANT_CARRO, int(3), YES, , ,
DESCRICAO, varchar(1000), YES, , ,
STATUS, char(1), YES, , ,
FILE_LOCAL, varchar(20), NO, , ,
O que esta acontecendo, é que tudo que é string aparece na tabela que mostro para o usuário, agora não consigo trazer os campos ID_CLI, ID_MOT ...
Estou mostrando essa tabela assim:
<?php if (count($this->listagem) > 0): ?>
<table class="table table-striped table-hover table-condensed">
<tr>
<th class="text-sm text-primary">ID</th>
<th class="text-sm text-primary">DATA</th>
<th class="text-sm text-primary">HORA</th>
<th class="text-sm text-primary">CLIENTE</th>
<th class="text-sm text-primary">TIPO SERVICO</th>
<th class="text-sm text-primary">LOCALIZADOR</th>
<th class="text-sm text-primary">AÇÕES</th>
</tr>
<?php foreach ($this->listagem as $v): ?>
<tr>
<th class="text-sm"><?php echo $v->getIDSERVICO(); ?></th>
<th class="text-sm"><?php echo $v->getDATA_INICIO()->format("d/m/Y"); ?></th>
<th class="text-sm"><?php echo $v->getHORA_INICIO()->format("H:i"); ?></th>
<th class="text-sm"><?php echo $v->getID_CLI(); ?></th>
<th class="text-sm"><?php echo $v->getID_MOT(); ?></th>
<th class="text-sm"><?php echo $v->getFILE_LOCAL(); ?></th>
<th class="text-sm"><a href=""
class="btn btn-xs btn-mini btn-primary">
<span i class="fa fa-pencil"></span></a>
<a href=""
class="btn btn-xs btn-danger btn-mini">
<span i class="fa fa-trash"></span></a>
</th>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
Se eu der um select direto no DB, ta tudo preenchido perfeitamente.Carregando comentários...