在编码器点火器中单击确定警报之前复制视图


Duplicated view before clicking OK alert in codeigniter

我的代码中遇到了一个lil问题,在我发送表单并弹出警报的那一刻,视图在下面复制了自己,我无法解决这个问题。

控制器:

function edit_profesor($id_profesor) {
    $id_profesor_submit = (int) $this->input->post('id_profesor', TRUE);
    if ($id_profesor_submit > 0) {
        $profesor_data['cedula'] = $this->input->post('cedula', TRUE);
        $profesor_data['nombre'] = $this->input->post('nombre', TRUE);
        $profesor_data['correo'] = $this->input->post('correo', TRUE);
        $profesor_data['telefono'] = $this->input->post('telefono', TRUE);
        $profesor_data['id_nivel'] = $this->input->post('nivel', TRUE);
        $result = $this->profesor->edit_profesor($profesor_data, $id_profesor_submit);
        if ($result) {
           $dato = array("message"=>"Se modificó el profesor exitosamente");
        } else {
           $dato = array("message1"=>"Error al intentar modificar profesor");
        }
        $this->load->view('profesor/add_profesor', $dato);
    }
    $result = $this->profesor->gets_profesor($id_profesor);
    $data['profesor'] = $result[0];
    $this->load->view('profesor/add_profesor', $data);
}

型:

function edit_profesor($profesor_data, $id_profesor) {
    $result = $this->db->get_where('profesor', array('id_profesor =' => "$id_profesor"));
    $return = null;
    if ($result->num_rows() > 0) {
        $this->db->where('id_profesor', $id_profesor);
        $this->db->update('profesor', $profesor_data);
        $user_data = array(
            'correo' => $profesor_data["correo"]
        );
        $this->db->where('id_profesor', $id_profesor);
        $this->db->update('users', $user_data);
        $return = TRUE;
    } else {
        $return = FALSE;
    }
    return $return;
}
function edit_profesor($id_profesor) {
    $id_profesor_submit = (int) $this->input->post('id_profesor', TRUE);
    if ($id_profesor_submit > 0) {
        $profesor_data['cedula'] = $this->input->post('cedula', TRUE);
        $profesor_data['nombre'] = $this->input->post('nombre', TRUE);
        $profesor_data['correo'] = $this->input->post('correo', TRUE);
        $profesor_data['telefono'] = $this->input->post('telefono', TRUE);
        $profesor_data['id_nivel'] = $this->input->post('nivel', TRUE);
        $result = $this->profesor->edit_profesor($profesor_data, $id_profesor_submit);
        if ($result) {
           $dato = array("message"=>"Se modificó el profesor exitosamente");
        } else {
           $dato = array("message1"=>"Error al intentar modificar profesor");
        }
        $this->load->view('profesor/add_profesor', $dato);
    }else{
    $result = $this->profesor->gets_profesor($id_profesor);
    $data['profesor'] = $result[0];
    $this->load->view('profesor/add_profesor', $data);
}
}

您没有放置其他条件,因此加载了两次。

基本上,

当您提交表单时,if statement true并且您第一次加载视图,并且视图再次加载到if statement之外第二次。添加else解决您的问题

function edit_profesor($id_profesor) 
{
    $id_profesor_submit = (int) $this->input->post('id_profesor', TRUE);
    if ($id_profesor_submit > 0) 
    {
        $profesor_data['cedula'] = $this->input->post('cedula', TRUE);
        $profesor_data['nombre'] = $this->input->post('nombre', TRUE);
        $profesor_data['correo'] = $this->input->post('correo', TRUE);
        $profesor_data['telefono'] = $this->input->post('telefono', TRUE);
        $profesor_data['id_nivel'] = $this->input->post('nivel', TRUE);
        $result = $this->profesor->edit_profesor($profesor_data, $id_profesor_submit);
        if ($result) {
           $dato = array("message"=>"Se modificó el profesor exitosamente");
        } else {
           $dato = array("message1"=>"Error al intentar modificar profesor");
        }
        $this->load->view('profesor/add_profesor', $dato);
    }
    else
    {
        $result = $this->profesor->gets_profesor($id_profesor);
        $data['profesor'] = $result[0];
        $this->load->view('profesor/add_profesor', $data);
    }
}