2
I am new to codeigniter and need to define my controller and model, so when calling the model inserir()
, the controller takes the last Generator ID of each table you want to do Insert. I’ll give you an example:
controller:
public function salvar(){
if($this->input->post('action') == 'cadastrar'){
$dados = array (
'COD_CIDADES' => '',
'DESCRICAO' => $this->input->post('cidade'),
'UF' => $this->input->post('uf'),
'CEP' => $this->input->post('cep'),
'COD_SITUACAO' => '0',
'ISS' => 'null',
'COD_PAIS' => '1',
'COD_IBGE' => $this->input->post('ibge')
);
$this->crud_model->inserir($tabela, $dados);
redirect('cidades/index');
}
model:
public function inserir($tabela, $dados_banco){
return $this->db->insert($tabela, $dados_banco);
}
In that case, the field COD_CIDADES
would have to receive the last ID (GEN_CIDADES)
, I know I could do an appointment like this:
"select gen_id(GEN_CIDADES, 0) as COD from RDB"."$"."DATABASE
", but I don’t know how to structure this so that I can use the model insert()
for all my Insert s.