我在我正在进行的系统中进行了验证,其中的场景是这样的:
如果员工在指定1和分支1上存在,他/她可以进入其他指定2和分支2,依此类推。我有这段代码:
以下是我的观点:
$emp_id = $this->input->post('emp_id');
$position =$this->input->post('d_id');
$branch =$this->input->post('b_id');
$date1 =$this->input->post('datepicker');
$date2=$this->input->post('datepicker2');
这是我的控制器:
$sql_test = $this->db->select("employee_id, designation_id,branch_id")->from("tb_emp_record2")->where("employee_id", $emp_id)->get();
foreach($sql_test->result() as $val){
$validate_employee = $val->employee_id;
$validate_position = $val->designation_id;
$validate_branch = $val->branch_id;
}
这是我的验证码示例:
if($validate_employee === $emp_id && $validate_position === $position && $validate_branch === $branch){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error1');
//$this->load->view('evaluation');
}elseif($validate_employee === $position && $validate_employee === $branch){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error2');
}elseif($position === $validate_employee && $validate_position === $emp_id){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error3');
}elseif($position === $validate_position && $emp_id === $validate_employee){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error4');
}elseif($branch === $validate_branch && $emp_id === $validate_employee){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error5');
}elseif($validate_employee === $date1 && $validate_employee === $date2){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error6');
}else{
$this->db->insert('tb_emp_record2', $insert_eval);
redirect('Mainx/evaluation_form/' .$emp_id. '/success' );
}
首先它在成功尝试后工作,因为我继续检查插入无效条目的错误。
答案 0 :(得分:0)
$employee_id = array();
$designation_id = array();
$branch_id = array();
$date_start = array();
$date_end = array();
//$sql_test = $this->db->select("emp_record_id,employee_id, designation_id,branch_id,date_start,date_end")->from("tb_emp_record2")->where("employee_id", $emp_id)->get();
$this->db->select("*");
$this->db->from("tb_emp_record2");
$this->db->join("tb_designation", "tb_emp_record2.designation_id = tb_designation.designation_id", "inner");
$this->db->join("tb_branch", "tb_emp_record2.branch_id = tb_branch.branch_id", "inner");
$this->db->where("employee_id", $emp_id );
$sql_test = $this->db->get();
foreach($sql_test->result() as $val){
$employee_id[] = $val->employee_id;
$designation_id[] = $val->designation_id;
$branch_id[] = $val->branch_id;
$date_start[] = $val->date_start;
$date_end[] = $val->date_end;
}
if(in_array($position, $designation_id) && in_array($branch, $branch_id) && in_array($date1, $date_start) && in_array($date2, $date_end)){
redirect('Mainx/evaluation_form/' .$emp_id. '/Error1');
}
else {
$this->db->insert('tb_emp_record2', $insert_eval);
redirect('Mainx/evaluation_form/' .$emp_id. '/success' );
}