代码如下,在视图文件中我将表单操作设为complete_survey()
,并且还提到控制器和模型如下,将值发布到模型中以便插入数据库或不。请有人帮助我,谢谢,或者我必须使用$this->survey_model->auto_save_projected($_POST);
控制器
public function complete_survey()
{
$this->survey_model->submit_survey($this->session, $_POST);
$this->survey_model->auto_save_projected();
$this->session->set_flashdata('message_success', 'Thanks for taking the survey!');
redirect('survey/home','message_success');
}
模型
function auto_save_projected(){
$projected = array(
'survey_id' => $surveyId,
'provisional_compare' => $post['higher'],
'percentage' => $post['range'],
'alternate_funding_mechanisms' => $post['high'],
'alternate_funding_expl' => $post['state_note'],
'projected_budget_created_date' => date('Y-m-d H:i:s'),
'projected_budget_modified_date' => date('Y-m-d H:i:s'),
);
}
答案 0 :(得分:0)
当您在控制器中调用$this->survey_model->auto_save_projected();
时,您的所有视图页面值也将在模型中可用。您无需使用$this->survey_model->auto_save_projected($_POST);
在模型中,您可以访问以下值:
function auto_save_projected(){
$projected = array(
'survey_id' => $surveyId,
'provisional_compare' => $this->input->post('higher'),
'percentage' => $this->input->post('range'),
'alternate_funding_mechanisms' => $this->input->post('high'),
'alternate_funding_expl' => $this->input->post('state_note'),
'projected_budget_created_date' => date('Y-m-d H:i:s'),
'projected_budget_modified_date' => date('Y-m-d H:i:s'),
);
}
但是你的模型$surveyId
来自哪里?你还没有从你的控制器传递这个值。检查一下。