提交表单后,如何使用参数重定向到PHP CodeIgniter中的列表视图页面?
当我在表单中输入数据并提交表单时,我试图重定向到我的列表视图页面 在我的例子中,我试图通过传递提交表单后,如何使用参数重定向到PHP CodeIgniter中的列表视图页面?,php,jquery,forms,codeigniter,redirect,Php,Jquery,Forms,Codeigniter,Redirect,当我在表单中输入数据并提交表单时,我试图重定向到我的列表视图页面 在我的例子中,我试图通过传递属性ID来输入特定属性的房间详细信息,提交表单后,它将重定向到属性列表,但我想重定向到房间列表 这是我的代码: 控制器: 型号: 视图: 更改控制器addRoom如下功能 public function addRoom($id) { $user = $this->ion_auth->user()->row(); $data['username'] = $user->
属性ID
来输入特定属性的房间详细信息,提交表单后,它将重定向到属性列表,但我想重定向到房间列表
这是我的代码:
控制器:
型号:
视图:
更改控制器addRoom
如下功能
public function addRoom($id)
{
$user = $this->ion_auth->user()->row();
$data['username'] = $user->username;
$data['user_id'] = $user->id;
$data['usertype'] = $user->type;
$data['title'] = 'Add New Rooms';
$data['roomtype'] =$this->p->selectRoomType();
$data['yesnotype'] = $this->p->selectYesNoType();
$data['bedroomtype'] = $this->p->selectBedroomType();
$data['property'] = $this->p->fetchProperty($id);
$data['views'] = $this->p->view_Room($id);
$data['property_id'] = $id;
$this->load->view('template/header', $data);
$this->load->view('Property/property_add_room', $data);
$this->load->view('template/footer');
}
从表单请求获取属性id
public function submitRoom()
{
$result = $this->p->submitAddRoom();
$id = $this->input->post('id'); //property id
if ($result) {
$this->session->set_flashdata('success_msg','Rooms added successfully');
}else{
$this->session->set_flashdata('error_msg','Faill to add Rooms');
}
//redirect(base_url('property'));
redirect(base_url('property/viewRoom'.$id));
}
将隐藏的属性id文件添加到表单中,如
<form action="<?php echo base_url('Property/submitRoom'); ?>" method="post" class="form-horizontal" autocomplete="off">
<input type="hidden" name="id" value="<?php echo $property_id; ?>">
</form>
changeredirect(基本url(“属性”)
到房间列表routeIt给出了一个错误,我只是在代码中注释掉这一行,因为我想显示与特定属性关联的房间列表(我正在传递属性ID)。使用重定向(base_url('property/viewRoom'$ID'))时发生了什么?您的viewRoom方法在property controller中的何处?请检查更新的代码。
public function addRoom($id)
{
$user = $this->ion_auth->user()->row();
$data['username'] = $user->username;
$data['user_id'] = $user->id;
$data['usertype'] = $user->type;
$data['title'] = 'Add New Rooms';
$data['roomtype'] =$this->p->selectRoomType();
$data['yesnotype'] = $this->p->selectYesNoType();
$data['bedroomtype'] = $this->p->selectBedroomType();
$data['property'] = $this->p->fetchProperty($id);
$data['views'] = $this->p->view_Room($id);
$data['property_id'] = $id;
$this->load->view('template/header', $data);
$this->load->view('Property/property_add_room', $data);
$this->load->view('template/footer');
}
public function submitRoom()
{
$result = $this->p->submitAddRoom();
$id = $this->input->post('id'); //property id
if ($result) {
$this->session->set_flashdata('success_msg','Rooms added successfully');
}else{
$this->session->set_flashdata('error_msg','Faill to add Rooms');
}
//redirect(base_url('property'));
redirect(base_url('property/viewRoom'.$id));
}
<form action="<?php echo base_url('Property/submitRoom'); ?>" method="post" class="form-horizontal" autocomplete="off">
<input type="hidden" name="id" value="<?php echo $property_id; ?>">
</form>