Edit a record using a form (ajax, codeigniter)

0

I have in my table filled by a query and a foreach in this table after filling it with records, I have a button to edit which opens a modal and from there edit the record.

The problem is that when you open the modal, you do not load the input with the data from that record and show this error Message: Trying to get property of non-object .

this is my query to fill the table

public function lineas4() { 

    $this->db->order_by('depto', 'asc');
    $this->db->order_by('nombre', 'asc');
    // $this->db->where('depto', 422);
    $query_lineas4=$this->db->get('lineas');

    if ( $query_lineas4->num_rows > 0 ) {
        return $query_lineas4->result();
    }
    return false;
}

The edit button that appears in the table:

<a href="#" class="btn btn-warning btn-xs editar" title="Editar"><span class="glyphicon glyphicon-edit"> Editar</span></a>

the function that triggers the edit button:

function getEditarLinea(){
    var id_linea = $('#id_linea').val();

    $.ajax({
        url: "<?=base_url('departamentos/getEditarLinea')?>",
        type: 'post',
        data: {id : id_linea},
        contentType:false,
        dataType:false,
        processData:false,
        success: function (respuesta){
            $("#myModalEditar").modal('show');
            $("#frmEditar").empty().append(respuesta);
        }
    });
    return false;
}

the function in the controller:

public function getEditarLinea(){
    $data['query'] = $this->modelo->getEditar();
    $this->load->view('departamentos/lin_form_editar', $data);
}

the function with the query in the model that will bring the record when it is equal to the selected id:

public function getEditar(){
    // var_dump($this->input->post('id'));
    $this->db->where('id_linea', $this->input->post('id'));
    $query=$this->db->get('lineas');

    if ($query->num_rows() > 0 ) {
        return $query->row();
    }
    return false;
}

the modal that loads the controller:

<?php $row = $query; 

var_dump ($ row); ? >

 

                          ×             Edit Production Line                  

        <div class="form-group">
            <label for="depto" class="col-lg-2 control-label">Departamento</label>
            <div class="col-lg-8">
                <input type="text" name="depto" id="depto" class="form-control" value="<?=$row->depto?>" placeholder="Departamento">
            </div>
        </div>

        <div class="form-group">
            <label for="nombre" class="col-lg-2 control-label">Nombre</label>
            <div class="col-lg-8">
                <input type="text" name="nombre" id="nombre" class="form-control" value="<?=$row->nombre?>" placeholder="Nombre">
            </div>
        </div>

        <div class="form-group">
            <label for="codigo" class="col-lg-2 control-label">Código</label>
            <div class="col-lg-8">
                <input type="text" name="codigo" id="codigo" class="form-control" value="<?=$row->codigo?>" placeholder="Código">
            </div>
        </div>

        <!-- <div class="form-group"> 
            <label for="descripcion" class="col-lg-2 control-label">Tipo de Documento</label>
            <div class="col-lg-8">
                <input type="text" name="descripcion" id="descripcion" class="form-control" value="<?=$row->descripcion?>" placeholder="Nombre del Departamento">
            </div>
        </div>-->



    </div>
    <div class="modal-footer">
        <input type="text" name="id" id="id" value="<?=$row->id_linea?>" />
        <button type="button" class="btn btn-default" data-dismiss="modal">Cerrar</button>
        <button id="btnEditarLinea"  class="btn btn-primary">Guardar Cambios</button>
    </div>
</div><!-- /.modal-content -->

Thanks for your time, colleagues.

    
asked by Irvin Olaff 29.06.2017 в 19:54
source

0 answers