获取代码生成器的活动日志

问题描述 投票:0回答:1

我尝试根据用户输入的更改在Codeigniter中创建活动日志,并产生这样的输出

Output : User1 Changes: Address (Street A) becomes (street B), date of birth (March 10, 2000) becomes (March 20, 2000), Phone number (0000) becomes (11111).

提交表单时,我可以找出哪些数据已更改,例如,地址从地址A更改为地址B。我想在数据库中存储日志。我也许可以将数据输入数据库,但是我仍然不知道如何获取输出数据,我尝试使用jQuery,但没有成功。 Codeigniter中有执行此功能的功能吗?

这是我的输入表格。

 <?php echo form_open(base_url('update_profile'), 'class="form-horizontal"');  ?> 
  <label for="address">Address:</label><br>
  <input type="text" id="address" name="address" value="Street B"><br>
  <input type="hidden" id="old_address" name="old_address" value="Street A"><br>

  <label for="birth">Date Birth:</label><br>
  <input type="text" id="birth" name="birth" value="March 20, 2000"> 
  <input type="hidden" id="old_birth" name="old_birth" value="March 10, 2000"> 

  <label for="phone">Phone number:</label><br>
  <input type="text" id="phone" name="phone"  value="11111">
  <input type="hidden" id="old_phone" name="old_phone" value="0000">

  <label for="email">Email:</label><br>
  <input type="email" id="email" name="email">
<?php echo form_close(); ?>

我的控制器

public function update_profile(){

        $is = $this->session->userdata('id');
        $this->form_validation->set_rules('phone', 'Phone', 'trim');

        if ($this->form_validation->run() == FALSE) {
                $errors = validation_errors();
                echo $errors;
        }
        else{
            $data = array(
                 'address' => $this->input->post('address'),
                 'birth' => $this->input->post('birth'),
                 'phone' => $this->input->post('phone'),
                 'email' => $this->input->post('email'),

            );

            $data   = $this->security->xss_clean($data);
            $result = $this->data_user->update_model_profile($data, $id);
            $result = true;

            if ($result) {
                echo $result;
            }
        }  
}   

这是我的模特。

    public function update_model_profile($data, $id){
        $this->db->where('user_id', $id);
        $this->db->update('data_profile', $data);
        return true;
    }   
javascript jquery mysql codeigniter
1个回答
0
投票

您可以将从数据库中获取的数据的副本保留在数组中,然后将其与表单提交的数据进行比较,并可以获取用户更改的值。

© www.soinside.com 2019 - 2024. All rights reserved.