![](/img/trans.png)
[英]function is not getting updated value of variable from another function in codeigniter
[英]insert variable value to database from another function in codeigniter?
在这里我需要一些帮助。
这是我的控制器:
function result_selected_abc_data(){
$this->auth->restrict();
$this->load->model('usermodel');
$this->load->model('productmodel');
$level=$this->session->userdata('level');
$this->load->library('form_validation');
$this->form_validation->set_rules('date1','Tanggal Di Masukkan','trim|required');
$this->form_validation->set_rules('date2','Tanggal Belum Di Masukkan','trim|required');
$this->form_validation->set_error_delimiters('<span style="color:#FF0000;">','</span>');
if($this->form_validation->run() == false){
$data['parent']=$this->usermodel->get_data_parent_menu($level);
$data['first_child'] = $this->usermodel->get_data_first_child_menu($level);
$data['second_child'] = $this->usermodel->get_data_second_child_menu($level);
$data['third_child'] = $this->usermodel->get_data_third_child_menu($level);
$data['fourth_child'] = $this->usermodel->get_data_fourth_child_menu($level);
$data['fifth_child'] = $this->usermodel->get_data_fifth_child_menu($level);
$data['sixth_child'] = $this->usermodel->get_data_sixth_child_menu($level);
$data['seventh_child'] = $this->usermodel->get_data_seventh_child_menu($level);
$this->template->display('ABC_select_date',$data);
}else{
$data['selected_date']= array(
'date1' => $this->input->post('date1'),
'date2' => $this->input->post('date2')
);
$date1=$this->input->post('date1');
$date2=$this->input->post('date2');
$data['ABC_report_result']= $this->productmodel->get_ABC_data_based_on_date($date1,$date2);
$this->template->display('ABC_select_data_result',$data);
}
}
我想将$ data ['ABC_report_result']值插入数据库的另一个功能,比如说保存abc():
function save_abc(){
**what should I make in here so I can get $data['ABC_report_result'] value and save it to database?**
}
我该怎么做? 谢谢您的帮助。
在您的控制器中
function save_abc(){
$ArrData = array(
'database_column'=>'value',
'database_column2'=>'value2',
);
$this->your_model->your_function($ArrData);
}
在您的模型中
public function your_function($data=''){
$this->db->insert('your_table',$data);
}
更新解决方案您可以做一件事在视图文件中,将$ date值保存在隐藏字段中,并创建一个按钮,保存调用操作save_abc()的数据,现在您可以执行
function save_abc(){
$this->load->model('productmodel');
$date1=$this->input->post('date1'); //data from hidden field
$date2=$this->input->post('date2'); //data from hidden field
$result = $this->productmodel->get_ABC_data_based_on_date($date1,$date2);
$this->your_model->your_save_function($result);
}
在CodeIgniter中,您的输入对象可以全局访问! 因此,如果您需要save_abc中的数据,为什么不尝试在目标函数中插入input-> post()方法?
尝试这个:
function result_selected_abc_data()
{
$this->auth->restrict();
$this->load->model('usermodel');
$this->load->model('productmodel');
$level=$this->session->userdata('level');
$this->load->library('form_validation');
$this->form_validation->set_rules('date1','Tanggal Di Masukkan','trim|required');
$this->form_validation->set_rules('date2','Tanggal Belum Di Masukkan','trim|required');
$this->form_validation->set_error_delimiters('<span style="color:#FF0000;">','</span>');
if($this->form_validation->run() == false){
$data['parent']=$this->usermodel->get_data_parent_menu($level);
$data['first_child'] = $this->usermodel->get_data_first_child_menu($level);
$data['second_child'] = $this->usermodel->get_data_second_child_menu($level);
$data['third_child'] = $this->usermodel->get_data_third_child_menu($level);
$data['fourth_child'] = $this->usermodel->get_data_fourth_child_menu($level);
$data['fifth_child'] = $this->usermodel->get_data_fifth_child_menu($level);
$data['sixth_child'] = $this->usermodel->get_data_sixth_child_menu($level);
$data['seventh_child'] = $this->usermodel->get_data_seventh_child_menu($level);
$this->template->display('ABC_select_date',$data);
}
else
{
$data['selected_date']= array(
'date1' => $this->input->post('date1'),
'date2' => $this->input->post('date2')
);
$date1=$this->input->post('date1');
$date2=$this->input->post('date2');
$data['ABC_report_result']= $this->productmodel->get_ABC_data_based_on_date($date1,$date2);
$this->productmodel->save_abc_data($data['ABC_report_result']);
$this->template->display('ABC_select_data_result',$data);
}
}
我在这里缺少明显的东西吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.