我是codeigniter的新手,我正在寻找一种将'reg_uad' => $this->input->post('uad')
分配给uri段的方法。有人能帮我解决这个问题吗。
public function reg()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('index', 'AL Index Number', 'required');
$this->form_validation->set_rules('mobile', 'Mobile Number', 'required');
$this->form_validation->set_rules('name', 'Name', 'required');
if($this->form_validation->run() == FALSE) {
$this->load->view('reg');
} else
{
//insert the contact form data into database
$data = array(
'reg_index' => $this->input->post('index'),
'reg_mobile' => $this->input->post('mobile'),
'reg_name' => $this->input->post('name'),
'reg_uad' => $this->input->post('uad'),
'reg_date' => date('Y-m-d H:i:s')
);
if ($this->db->insert('tbl_reg', $data))
{ // success
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">We received your message! Will get back to you shortly!!!</div>');
redirect('main/uad_code');
}
else
{
// error
$this->session->set_flashdata('msg','<div class="alert alert-danger text-center">Oops! Some Error. Please try again later!!!</div>');
redirect('main/reg');
}
}
}
你可以这样做重定向时分配
有两种方法可以在URL中传递变量1在url 中具有变量名
redirect('main/uad_code?reg_id=3');
要访问uad_code方法中的该值,
$id=$this->get('reg_id');
2.您可以在url 中传递任意数量的变量
redirect('main/uad_code/$regId/3/5');
在这里,您可以使用uri段选项访问变量
控制器名称将是uri中的第一个段,
methodname将是uri 中的第二个段
E.g对于以上
$contName = $this->uri->segment('1') // assigns main to $conName
$methName = $this->uri->segment('2') // assigns uad_code to $methName
$red_id = $this->uri->segment->('3') // assigns value in $regId to $reg_id
$exVar = $this->uri->segment->('4') // assigns 3 to $exVar
$exVar1 = $this->uri->segment->('5') // assigns 5 to $exVar1