I'm new to codeigniter and I need to define my controller and model, so when calling the model inserir()
, the controller takes the last ID of the generator of each table that wants to do the insert. Let me 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 this case, the field COD_CIDADES
would have to receive the last ID (GEN_CIDADES)
, I know it would be possible to make an appointment like this:
"select gen_id(GEN_CIDADES, 0) as COD from RDB"."$"."DATABASE
", but I do not know how to structure this so that I can use the insert()
model for all my inserts.