如何使用codeigniter获取多个参数

时间:2016-12-23 17:53:15

标签: php codeigniter

我在搜索方法时遇到更多参数的问题。 这是我的网址 - >

http://localhost:8080/sewarumah/search/searchIndex?state=1&city=2&poskod=90002&jenisRumah=Banglo0&bilangan=2

所以在这里我想获取所有参数并传递给模型。

这是我的控制器

public function index($state,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan)
{
$state=$this->input->get("state");
$data['search_result'] = $this->m_search->searchIndex($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan);
$this->load->view('senarai-rumah', $data,$state);
}

这是我的模特

 public function searchIndex($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan){
    $sql = "select * from house_rent where houseStateId = ? and houseDistrictId = ? and housePostcode = ? and houseType = ? and housePeople = ?;";
    $query = $this->db->query($sql, array($searchState,$searchCity,$searchPoscode,$searchJenisRumah,$searchBilangan));
  return $query->result();
  }

所以错误显示 消息:未定义的变量:state

1 个答案:

答案 0 :(得分:0)

这些变量都没有实际定义,除非你在路线中这样做(这看起来很愚蠢)。您可以通过$this->input->get()方法获取所有内容,如下所示:

public function index()
{
   $state=$this->input->get("state");
   $city=$this->input->get("city");
   $postcode=$this->input->get("postcode");
   $jenisRumah=$this->input->get("jenisRumah");
   $bilangan=$this->input->get("bilangan");
   $data['search_result'] = $this->m_search->searchIndex($state,$city,$postcode,$jenisRumah,$bilangan);
   $this->load->view('senarai-rumah', $data, $state);
}