2017-11-30 1 views
0

데이터를 양식에 입력하고 양식을 제출할 때 목록보기 페이지로 리디렉션하려고합니다. 내 경우 양식을 제출 한 후 매개 변수를 사용하여 PHP CodeIgniter의 목록보기 페이지로 리디렉션하는 방법?

, 나는 property ID을 전달하여하고는 속성 목록로 리디렉션됩니다 폼에 제출 한 후 특정 속성에 대한 공간 정보를 입력하기 위해 노력하고있어,하지만 난 방 목록로 리디렉션합니다.

컨트롤러 :

public function viewRoom($id) 
{ 
    $user = $this->ion_auth->user()->row(); 
    $data['username'] = $user->username; 
    $data['user_id'] = $user->id; 
    $data['usertype'] = $user->type; 

    $data['title'] = 'View Rooms'; 

    $data['property'] = $this->p->fetchProperty($id); 
    $data['views'] = $this->p->view_Room($id); 

    $this->load->view('template/header', $data); 
    $this->load->view('Property/property_view_room', $data); 
    $this->load->view('template/footer'); 
} 

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); 

    $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(); 

    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)); 
} 

모델 :

public function view_Room($id) 
{ 
    $query =$this->db->query('call fetch_View_Room(?)',$id); 
    if ($query->num_rows()>0) { 
     $data =$query->result(); 
     $query->next_result(); 
     $query->free_result(); 
     return $data; 
    } else { 
     return false; 
    } 
} 

public function submitAddRoom() 
{ 
    $sql ="call insert_Room(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 
            ?, ?, ?, ?, ?, ?, ?)"; 
    $this->db->query($sql, array(
     'user_id'=>$this->input->post('user_id'), 
     'room_landlord_id'=>$this->input->post('room_landlord_id'), 
     'room_property_id'=>$this->input->post('room_property_id'), 
     'room_custom_number'=>$this->input->post('room_custom_number'), 
     'room_name'=>$this->input->post('room_name'), 
     'room_type'=>$this->input->post('room_type'), 
     'room_location'=>$this->input->post('room_location'), 
     'room_notes'=>$this->input->post('room_notes'), 
     'room_size'=>$this->input->post('room_size'), 
     'room_fire_escape'=>$this->input->post('room_fire_escape'), 
     'room_fire_doors'=>$this->input->post('room_fire_doors'), 
     'room_bedroom_type'=>$this->input->post('room_bedroom_type'), 
     'room_wc'=>$this->input->post('room_wc'), 
     'room_sink'=>$this->input->post('room_sink'), 
     'room_shower'=>$this->input->post('room_shower'), 
     'room_extractor_fan'=>$this->input->post('room_extractor_fan'), 
     // 'room_images'=>$this->input->do_upload('room_images'), 
     'room_double_door'=>$this->input->post('room_double_door') 
    )); 
    if ($this->db->affected_rows() > 0) 
    { 
     return true; 
    } else { 
     return false; 
    } 
} 

보기 :

여기

내 코드입니다
<form action="<?php echo base_url('Property/submitRoom'); ?>" method="post" class="form-horizontal" autocomplete="off"> 

</form> 

매개 변수를 전달하는 동안 실수를 했습니까? submit() 함수에서 매개 변수를 전달하는 방법은 무엇입니까?

업데이트 : 사전에 도움의 모든 종류의 환영 enter image description here

, 감사합니다.

+0

변화와 같은 양식으로 제출 속성 ID의 숨겨진'리디렉션 (base_url ('property'));'방 목록 경로로 –

+0

그것은 n 오류, 특정 속성과 연관된 방 목록을 표시하려고하기 때문에 코드의 해당 줄을 주석으로 처리합니다 (속성 ID를 전달 중입니다). –

+0

redirect (base_url ('property/viewRoom'. $ id));를 사용했을 때 어떤 현상이 발생 했습니까? ? 그리고 속성 컨트롤러에서 viewRoom 메서드는 어디에 있습니까? – TimBrownlaw

답변

1
양식 요청에서 속성 ID를 얻을이

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'); 
} 

같은 컨트롤러 addRoom 기능을 변경

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> 
관련 문제