提交 Codeigniter 后如何获取引导 html 表单的详细视图
Posted
技术标签:
【中文标题】提交 Codeigniter 后如何获取引导 html 表单的详细视图【英文标题】:How to get Detail view of bootstrap html form after submit Codeigniter 【发布时间】:2014-03-15 20:32:18 【问题描述】:我有一个引导表单,在填充数据后,它成功地插入到数据库中。现在我想显示带有填充数据的表单的详细视图,但它在提交后将我带回创建视图,并将数据添加到数据库。我想我的网站网址有问题。为了更好地理解,我附上我的代码。
我的创建视图文件代码是:
<form class="form-horizontal" id="job" action="<?php echo site_url('admission/add_students')?>" method="POST" name="job">
作为控制者(准入):
function add_students()
$this->load->model('admission_detail_model');
$data=array(
'student_id'=>'La-0002'.$this->input->post('student_id'),
'father_name'=>$this->input->post('father_name'),
'mother_name'=>$this->input->post('mother_name'),
'fname'=>$this->input->post('first_name'),
'lname'=>$this->input->post('Last_name'),
'place_of_birth'=>$this->input->post('place_birth'),
'mother_tounge'=>$this->input->post('mother_tounge'),
'd_o_b'=>$this->input->post('DOB'),
'nationality'=>$this->input->post('nationality'),
'religion'=>$this->input->post('religion'),
'sc_st_obc'=>$this->input->post('sc_st_obc'),
'caste'=>$this->input->post('caste'),
'address'=>$this->input->post('address'),
'admitting_student'=>$this->input->post('Admit_std'),
'father_edu_qual'=>$this->input->post('father_q'),
'mother_edu_qual'=>$this->input->post('mother_q'),
'annual_income'=>$this->input->post('annual_income'),
'father_occupation'=>$this->input->post('father_occupation')
);
$this->admission_detail_model->add_students($data);
$this->index();
型号:
class Admission_detail_model extends CI_Model
function add_students($data)
$this->db->insert('students',$data);
return;
一切正常我只想在提交表单后添加详细视图,而不是另一个创建表单视图。对于详细视图,我在基本控制器(准入)中定义了控制器:
public function detailed_admission()
$this->load->helper('url');
$this->load->view('Header');
$this->load->view('side_menu');
$this->load->view('admission/detailted_view');
$this->load->view('footer');
当我尝试在创建视图文件中替换站点 url 时
"<?php echo site_url('admission/detailted_view')?>"`
它不会在没有任何数据的情况下直接将数据库中的数据重定向到该视图。
这是我的第一个问题,所以如果我犯了任何错误,请避免。 谢谢你的帮助
【问题讨论】:
【参考方案1】:在代码中检查我的 cmets。
function add_students()
$this->load->model('admission_detail_model');
$data=array(
'student_id'=>'La-0002'.$this->input->post('student_id'),
'father_name'=>$this->input->post('father_name'),
'mother_name'=>$this->input->post('mother_name'),
'fname'=>$this->input->post('first_name'),
'lname'=>$this->input->post('Last_name'),
'place_of_birth'=>$this->input->post('place_birth'),
'mother_tounge'=>$this->input->post('mother_tounge'),
'd_o_b'=>$this->input->post('DOB'),
'nationality'=>$this->input->post('nationality'),
'religion'=>$this->input->post('religion'),
'sc_st_obc'=>$this->input->post('sc_st_obc'),
'caste'=>$this->input->post('caste'),
'address'=>$this->input->post('address'),
'admitting_student'=>$this->input->post('Admit_std'),
'father_edu_qual'=>$this->input->post('father_q'),
'mother_edu_qual'=>$this->input->post('mother_q'),
'annual_income'=>$this->input->post('annual_income'),
'father_occupation'=>$this->input->post('father_occupation')
);
//To insert the record in the database
$this->admission_detail_model->add_students($data); after
//open the detail view page
// $this->index(); why did you call index function ??
$this->detailed_admission(); //call detailed function just after the form submission or you can perform redirect('admission/detailed_admission')
【讨论】:
katiyar 你好,现在它工作正常我只是错过了我再次加载索引函数,所以我得到了创建视图。感谢您的回答,它有效以上是关于提交 Codeigniter 后如何获取引导 html 表单的详细视图的主要内容,如果未能解决你的问题,请参考以下文章
CodeIgniter 2.1.3 - 表单助手 - 无法提交数据
在 codeigniter 中提交一次后,在每次刷新时停止表单提交