0

当我使用 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;
}
4

1 回答 1

0

$this->session->set_flashdata("success_msg", "成功插入设置"); redirect(''admin/setting',$data');

然后在视图中

session->flashdata('success_msg')): ?> × session->flashdata('success_msg'); ?>
于 2019-01-21T08:05:32.810 回答