Insert an id from another, codeigniter

Asked

Viewed 41 times

0

Hello, good afternoon to you!! I need help in a following case about codeigniter, I have my Clients table and my Calls table, in the register of a call, I need to reference it to a client, the "call record" is in the client’s View, How do I get the id of this client and insert it into the table called ? I have a column called id_client, that serves to make this "Join", someone can help me?

at the moment my Insert is like this

function novoChamado(){
  $data = array(
    'chamado_atividade'          => $this->input->post('chamado_atividade'),
    'chamado_duracao_minuto'     => $this->input->post('chamado_duracao_minuto'),
    'chamado_duracao_hora'       => $this->input->post('chamado_duracao_hora'),
    'chamado_assunto'            => $this->input->post('chamado_assunto'),
    'chamado_data'               => $this->input->post('chamado_data'),
    'chamado_hora'               => $this->input->post('chamado_hora'),
    'chamado_atendente_rf'       => $this->input->post('chamado_atendente_rf'),
    'chamado_atendente_cliente'  => $this->input->post('chamado_atendente_cliente'),
    'chamado_obs'                => $this->input->post('chamado_obs'),
    'chamado_telefone'           => $this->input->post('chamado_telefone'),
    'chamado_email'              => $this->input->post('chamado_email'),
    'chamado_id_cliente'         => ??????

my function of listing calls is like this

public function listarChamadosCliente($cliente_id){

  $this->db->select('*');
  $this->db->from('chamado');
  $this->db->join('cliente', 'cliente.cliente_id = chamado.chamado_id_cliente');
  $this->db->where('chamado.chamado_id_cliente ='.$cliente_id );
  $this->db->order_by('chamado_data');
  $query = $this->db->get();
  if($query->num_rows() < 1){
    return FALSE;
  }
  return $query->result();
}

Thanks in advance!!!

  • When you load the client view you don’t save an identifier, in the url, hidden field, session (only the last one I don’t like) or some other way?

  • I save yes to the url, so it’s an example with the id of nº 10 http://localhost/RFCRM/C_client/display/10

  • So I didn’t understand your question, you’re passing the handle but can’t get it in the controller?

  • "localhost/RFCRM/C_client/newChamado/10" receiving as parameter the identifier would already solve. Or adding this id as a hidden field in the form (not ideal but works) would also solve

  • then would it look like this? Call newFunction($cliente_id){ $data = array( [...] 'call_id_client' => $cliente_id

  • That way I believe you already solve your problem

  • And if it serves as a tip take a look at this guy https://github.com/fadakar/codeigniter_viewModel_binder Help bind the form values to the object in a simpler way.

  • gave this Too few Arguments to Function M_called::newChamado(), 0 passed in htdocs RFCRM application controllers C_called.php on line 20 and Exactly 1 expected

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.