【发布时间】:2020-03-27 10:57:52
【问题描述】:
我正在学习将 codeigniter 与 rest_controller 库一起使用。
我正在搜索更新我的数据库中表中的一些值。
我的控制器中有:
public function guest_patch(){
$idperson = $this->uri->segment(3);
$person = array(
'fiscalcode' => $this->input->post('fiscalcode'),
'name' => $this->input->post('name'),
'surname' => $this->input->post('surname')
);
$this->load->model('Person_model');
$data = $this->Person_model->patch($idperson, $person);
$this->response($data);
}
在我的模型中:
public function patch($idperson, $person){
$this->fiscalcode = $person['fiscalcode'];
$this->name = $person['name'];
$this->surname = $person['surname'];
$result = $this->db->update('Persons', $this, array('id' => $idperson));
if($result){
return("Dati aggiornati");
}
}
我有两个问题要问你:
1) 在这种情况下,当我启动 update 方法时,我的数据库中的值将被删除(或用 0 替换)。事实上,我试图在我的模型中打印 $person 并且我传递的所有值(使用邮递员)都是空的。而如果我在控制器中手动插入数据,例如:
'fiscalcode' =>'NewFiscalCode'
db 中的数据被更新。 如何更新从表单数据中恢复的值(在我使用邮递员传递的那一刻)?
2) 如果我不想更新一个值,所以我将一个字段留空(例如,我在表单数据中只写了姓名和姓氏,但我不想更改财务代码字段),数据库中有关此字段“财政代码”的数据将被消除?
谢谢
【问题讨论】:
标签: php rest codeigniter