【发布时间】:2020-09-02 19:48:57
【问题描述】:
我尝试根据用户输入的更改在 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;
}
【问题讨论】:
-
要从数据库中获取数据,您只需在模型中创建一个函数,如更新函数,然后您可以在控制器中获取它或者您想要其他东西??
-
如何获取输出数据是什么意思?请解释您的问题
-
我的意思是,当我点击提交时,我可以找出哪些数据发生了变化,例如地址,从地址 A 到地址 B。就像这个 stackoverflow.com/questions/29118178/… 一样,但对于所有输入。 @sauhardnc
-
谢谢,但我不会从数据库中获取数据。我想获取日志数据,我可以找出哪些数据已更改。 @NadeemIjaz
标签: javascript jquery mysql codeigniter