【问题标题】:How to get more than one parameter using codeigniter如何使用 codeigniter 获取多个参数
【发布时间】:2023-03-08 11:38:01
【问题描述】:

我在执行搜索方法时无法获取更多参数。 这是我的网址 ->

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

所以错误显示 消息:未定义变量:状态

【问题讨论】:

    标签: php codeigniter


    【解决方案1】:

    实际上没有定义这些变量,除非您在路线中执行它们(这看起来很愚蠢)。您可以像这样从$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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-09-24
      • 1970-01-01
      • 2022-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多