我在Codeigniter中进行简单的CRUD操作。
这是我的控制器:
public function areaEdit($area_id)
{
$this->global['pageTitle'] = 'Area Edit';
$data['areaEdit'] = $this->um->areaEdit($area_id);
$this->loadViews("utilities/area/areaEdit", $this->global, $data , NULL);
}
public function updateArea($area_id='area_id')
{
$area_name = $this->input->post('area_name');
$area_abbr = $this->input->post('area_abbr');
$this->form_validation->set_rules('area_name', 'Area Name', 'trim|required');
$this->form_validation->set_rules('area_abbr', 'Area Abbrevation', 'trim');
if ($this->form_validation->run() == FALSE) {
$this->areaEdit($area_id);
} else {
$area_name = ucwords(ucfirst($this->security->xss_clean($area_name)));
$area_abbr = ucwords(ucfirst($this->security->xss_clean($area_abbr)));
$data = array('area_name' => $area_name, 'area_abbr' => $area_abbr);
$result = $this->um->updateArea($data, $area_id);
if ($result) {
$this->session->set_flashdata('success', '<b>'.$area_name.'</b> updated successfully on '.date('d/m/Y H:i:s'));
} else {
$this->session->set_flashdata('error', 'Something wrong! Please try again.');
}
redirect(base_url('utilities/areaList'));
}
}
public function deleteArea($area_id='area_id')
{
$result = $this->um->deleteArea($data, $area_id);
if ($result) {
$this->session->set_flashdata('success', '<b>'.$area_name.'</b> deleted successfully on '.date('d/m/Y H:i:s'));
} else {
$this->session->set_flashdata('error', 'Something wrong! Please try again.');
}
redirect(base_url('utilities/areaList'));
}
这是我的模型:
public function areaEdit($area_id)
{
$this->db->select("*");
$this->db->from("tbl_area");
$this->db->where("area_id", $area_id);
$query = $this->db->get();
return $query->row();
}
public function updateArea($data, $area_id)
{
$this->db->where("$area_id", $area_id);
$this->db->update("tbl_area", $data);
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
public function deleteArea($area_id='area_id')
{
$this->db->where("area_id", $area_id);
$this->db->delete("tbl_area");
if ($this->db->affected_rows() > 0) {
return true;
} else {
return false;
}
}
当我运行这个脚本时,它会给我一个错误,它会在控制器中用于更新功能和删除功能。
在我犯错的地方,我没有得到它?
欢迎任何形式的帮助,提前谢谢。
答案 0 :(得分:1)
希望这会对您有所帮助:
不匹配的参数 :您从控制器传递了两个参数,但模型calculate = _.debounce(() => {
const inputOne = $('#inputone').val();
const inputTwo = $('#inputtwo').val();
if (inputOne !== '' && inputTwo !== '') {
const result = parseFloat(inputOne / inputTwo);
alert(result);
}
}, 300);
$('#inputone').keypress(calculate);
$('#inputtwo').keypress(calculate);
中只有一个参数;
应该是这样的:
deleteArea()