이이 질문에 함수 add_newStaff에서CodeIgniter 폼 유효성 검사에서 코드 중복을 방지하는 방법은 무엇입니까?
function newStaff()
{
$data = array();
$data['departmentList'] = $this->department_model->list_department();
$data['branchList'] = $this->branch_model->list_branch();
$data['companyList'] = $this->company_model->list_company();
$this->load->view('staff/newstaff', $data);
}
function add_newStaff()
{
//when user submit the form, it will call this function
//if form validation false
if ($this->validation->run() == FALSE)
{
$data = array();
$data['departmentList'] = $this->department_model->list_department();
$data['branchList'] = $this->branch_model->list_branch();
$data['companyList'] = $this->company_model->list_company();
$this->load->view('staff/newstaff', $data);
}
else
{
//submit data into DB
}
}
(), 내가 양식 유효성 검사가 false를 반환하면 데이터베이스에서 모든 데이터를 다시로드 할 필요에 대한 직원 컨트롤러 기능의 샘플입니다. 두 개의 코드 사본을 유지해야하기 때문에 문제가 될 수 있습니다. 이 문제를 방지하기 위해 사용할 수있는 팁이 있습니까?
감사합니다.
와우 감사합니다. 나는이 방법을 전에는 생각할 수 없다. – cyberfly