当我使用 CodeIgniter 会话set_flashdata
并在数据库页面中插入数据时,会无限循环。但不使用set_flashdata
它就可以完美地工作。
$this->session->set_flashdata('success_msg', 'Successfully Inserted Settings');
redirect('admin/settings/sitesetting');
自动加载
$autoload['libraries'] = array('database', 'form_validation', 'email', 'session', 'encrypt', 'user_agent','pagination','Pdf');
控制器
public function sitesetting()
{
$data['title'] = 'Admin - Site Settings';
$data['setting'] = $this->AdminModel->selectalldata('tbl_settings');
$set = $data['setting'];
if(isset($_POST['submisetting'])){
$this->form_validation->set_rules('setting_text', 'Setting ', 'required');
if($this->form_validation->run() == FALSE){
$this->load->view('admin/setting',$data);
}else{
$value = $set[2]->id;
$data = array( "setting_value"=> $this->input->post('setting_text'));
$update = $this->AdminModel->updatedata('tbl_settings', 'id', $value, $data);
$this->session->set_flashdata('success_msg', 'Successfully Inserted Settings');
redirect('admin/settings/sitesetting');
}
}else{
$this->load->view('admin/setting',$data);
}
}
模型
function updatedata($table_name, $where, $id, $data){
$this->db->where($where, $id);
$this->db->update($table_name, $data);
return true;
}