Storage in several tables from a form in codeigniter

0

I have a base project that I do but I want to improve it, you will see: I came up with the easy idea that to register information of a client (which is divided into 4 tables in the BDD connected to each other) was to enter the data in 4 different forms: an initial form that recorded the data of the 1st table and when clicking on the next button, it will send the other form that collected the ID of the previous table and entered new ones and so on. And I feel (obviously) that it should not be like that, that there would be a more optimal way to do it.

It occurred to me (in advance I am relatively new in programming) to store the data in a variable or in a table where all the info is stored with an Array and then take it from there for its use.

If someone could give me some advice and if that is added with a link / example that would be better and grateful ...

What I have so far is this, is an example of insertion in a single table with a function that implements Joins's, What I intend is that globally in an update of the table customers can update in the table users:

MODEL

public function update($id_contratos_d, $data)
{
    $this->db->select("contratos.*, cli.*, usr.*");
    $this->db->where("contratos.id_contratos_d", "$id_contratos_d");

    $this->db->join("clientes cli", "contratos.cliente_id = cli.id_cliente");
    $this->db->join("usuarios usr", "cli.usuario_id = usr.id_usuarios");
    return $this->db->update("contratos", $data);

}

CONTROLLER

public function actualizar_usuario()
{
    $New_id_usuario = $this->input->post("New_id_usuario");
    $username       = $this->input->post("username");

    $data = array(
        'username' => $username,
    );

    if ($this->Clientes_model->update($New_id_usuario, $data)) {
        $this->session->set_flashdata("exito", "Se guardo la información");
        redirect(base_url() . "clientes/Clientes_controller");
    } else {
        $this->session->set_flashdata("error", "No se pudo guardar la informacion"); 
        redirect(base_url() . "clientes/Clientes_controller/editar/");
    }

}

VISTA

  <form action="<?php echo base_url();?>clientes/Clientes_controller/actualizar_usuario" method="POST">
<input type="hidden" value="<?php echo $contrato->id_usuarios;?>" name="New_id_usuario">

<div class="box-body">
  <div class="row">
    <div class="col-xs-8 <?php echo form_error('username') == true ? 'has-error': '';?>">
        <label for="username">Nombre de usuario:</label>
        <input type="text" class="form-control" id="username" name="username" value="<?php echo $contrato->username?>">
        <?php echo form_error("username","<span class='help-block'>","</span>");?>
    </div>
  </div>
</div>
<div class="box-footer">
  <button type="submint" class="btn btn-success"><span class="fa fa-check"></span> Guardar</button>
</div>

Thank you very much.

    
asked by González 09.03.2018 в 17:29
source

0 answers