【发布时间】:2014-04-04 09:48:30
【问题描述】:
我在 CI 中有一个方法,它基本上将用户添加到表中 - 如果发生任何表单验证,它会重新加载视图 - 如果成功,它会重新加载视图以显示用户已成功添加。如下图:
public function loadPeopleView(){
//loads unit page view
$this->load->model('people_model');
$people['people'] = $this->people_model->getPeople();
$this->load->view("header");
$this->load->view("people page/people_view", $people);
$this->load->view("footer");
}
public function addPerson(){
$this->form_validation->set_rules('personName', 'personName', 'required|min_length[6]|max_length[150]|trim|xss_clean');
$this->form_validation->set_rules('personPet', 'personPet', 'required|trim|min_length[3]|max_length[30]|xss_clean');
if($this->form_validation->run()){
$this->load->model('');
$this->people_model->addPerson();
$this->loadPeopleView();
} else{
//if validation fails - returns the peopl view this display error messages
$this->loadPeopleView();
}
}
我的问题是当有人添加一个人时浏览器仍然在: 本地主机/peoplecontroller/addperson
如果用户不断刷新页面 - 将继续添加大量人员 - 无论如何我可以将页面放回: 本地主机/人控制器/
无需使用重定向,因为我仍然希望出现来自表单验证的任何错误消息
【问题讨论】:
标签: php codeigniter url-redirection