通过URL直接访问页面会在codeigniter search

时间:2017-05-17 06:01:11

标签: forms codeigniter search

我正在开展一个项目,如果我尝试搜索查询它会显示结果,但如果我尝试通过相同的URL访问同一页面,则显示空白页面。非常感谢任何帮助。谢谢!

我的控制器

这是我的搜索功能

public function search($keyword = "default", $city = "NULL")
    {

            $keyword = $this->input->get();

            $data['city_name']  =   $keyword['city'];
            $data['service_name']   =   str_replace('-',' ',$keyword['search']);
            //echo "<pre>";print_r($data); die('kk');

// get sponsor data by city

    $data['sponsor']    =   $this->Home_model->getSponsor($keyword['city']);

            $data['packercontent'] =    $this->Home_model->getPackerContent($keyword['city']);
            $data['packers']  = $this->Home_model->get_results($keyword);
            //echo "<pre>";print_r($keyword);die;
            $data['info']           =   $this->Home_model->getSiteInfo();

            $data['page']   =   '';
            $this->load->view('viw_packers', $data);


    }

我的模态

     // get all packers according to city
     public function get_results($keyword = 'default')
      {

        $this->db->select('*');
        $this->db->like('service', str_replace('-',' ',$keyword['search']));
        $this->db->where('city', $keyword['city']);
        $query  = $this->db->get('pf_package');

        return $query->result();
      }

// get all sponsor according to city
      public function getSponsor($city)
      {
        $this->db->select('*');
        $this->db->where('sp_city',$city);
        $this->db->from('pf_sponsor');
        $query = $this->db->get();

        return $query->row();
      }

// get all packer content according to city
      public function getPackerContent($city)
      {
        $this->db->select('*');
        $this->db->where('city',$city);
        $this->db->from('pf_packers_content');
        $query = $this->db->get();

        return $query->row();
      }

我的观看文件

  <form class="form-inline" id="myForm" method="get" action="">
          <div class="form-group row nomargin">
                                <div class="servicewrap col-lg-5 col-md-5 col-sm-5 col-xs-12 nopadding">
              <select class="form-one-class" name="search" id="service">
               <option value="moving-locally">Moving Locally</option>
               <option value="moving-overseas">Moving Overseas</option>
               <option value="corporate-relocation">Corporate Relocation</option>
               <option value="commercial-relocation">Commercial Relocation</option>
               <option value="packaging-services">Packaging Services</option>
               <option value="storage-services">Storage Services</option>
             </select>
                                </div><!-- /.servicewrap -->

                                <div class="citywrap col-lg-5 col-md-5 col-sm-5 col-xs-12 nopadding">
                                    <input type="text" class="form-control" id="city" name="city" autocomplete="off" placeholder="select city">
              <div id="category-suggestions">
                   <div class="suggestions col-xs-12" id="category-autoSuggestionsList">

                   </div>
              </div>
            </div><!-- /.citywrap -->
                                <div class="buttonwrap col-lg-2 col-md-2 col-sm-2 col-xs-12 nopadding">
                                    <button type="submit" class="btn btn-default" id="search-button" >search</button>
                                </div><!-- /.buttonwrap -->
                            </div>
                        </form>

这是我的js代码

我通过js调用我的搜索表单操作。

<script>
$(document).ready(function(){
  $("#search-button").click(function(e){
    var city = $("#city").val();
    var lowerCity = '-'+city.toLowerCase();
    document.getElementById("myForm").action = "<?php echo base_url('search/packers-and-movers-in'); ?>"+lowerCity;
  });
});

</script>

1 个答案:

答案 0 :(得分:0)

这是你的控制器功能

public function search($keyword = "default", $city = NULL)
{
$data["sponcer"] = $this->your_model->searchByKeyword($keyword);
$data["packerContent"] = $this->your_model->searchByKeyword($city);

$this->load->view("yourview", $data);
}

这只是演示代码,您需要根据需要构建。你真的不需要$_GET来从querystring获取值。

如果您编写上面的代码,那么您的网址如下: http://localhost/profilehome/search/packers-and-movers-in-jaipur/Jaipur

查看此处的文档: https://www.codeigniter.com/user_guide/general/urls.html