搜索提交按钮在CodeIgniter中不起作用

时间:2016-07-19 07:21:35

标签: php codeigniter

我已经使用CodeIgniter构建了一个页面,它具有搜索功能和数据表。 每当我单击搜索按钮时,数据表将根据提交的参数进行相应更改。但它没有像我预期的那样工作。

这是我的模特

public function ocsmodel($biostype=null, $manufacture=null)
{
    // Loading second db and running query.
    if ($biostype==null and $manufacture == Null) {
        $this->ocs = $this->load->database('ocsweb', TRUE);
        return $this->ocs->select('ocslist.*')
                         ->from('ocslist')
                         ->limit(100)
                         ->get();            
    }
    else {
        if ($manufacture == "") {

        }
        else {
             $this->ocs = $this->load->database('ocsweb', TRUE);
            return $this->ocs->select('ocslist.*')
                             ->from('ocslist')
                             ->where('bios_type',$biostype)
                             ->where('smanufature',$manufacture)
                             ->limit(100)
                             ->get();   
        }

    }

}

这是我的控制器

public function ocslist()
{

    $manufactur ="";
    $biostype ="";


    if (isset($_POST['bios_type'])){
        $biostype = $this->input->post('bios_type');
        if (isset($_POST['manufacture'])){
            $manufactur = $this->input->post('manufacture');
        }

        $data['ocs'] = $this->assetmodel->ocsmodel()->result_array();

    } 
    else {
        $data['ocs'] = $this->assetmodel->ocsmodel($biostype,$manufactur)->result_array();  
    }


    $data['ocstype'] = $this->assetmodel->getocstype()->result_array();
    $data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
    $data['content'] = 'master/ocs_list';
    $this->load->view('template', $data, FALSE);    
}

这是我的观点

    <div class="right_col" role="main">
      <div class="">
        <div class="page-title">
          <!--<div class="title_left">
            <h3>
                  Master Department
                  <small>
                      List
                  </small>
              </h3>
          </div> -->
        </div>
        <div class="clearfix"></div>

      <div class = "row">

        <div class="col-md-12 col-sm-12 col-xs-12">
          <div class="x_panel">
            <div class="x_title">
              <h2>OCS INVENTORY LIST</h2>
              <ul class="nav navbar-right panel_toolbox">
                <li><a href="#"><i class="fa fa-chevron-up"></i></a>
                </li>
                <li class="dropdown">
                  <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false"><i class="fa fa-wrench"></i></a>
                </li>
                <li><a href="#"><i class="fa fa-close"></i></a>
                </li>
              </ul>
              <div class="clearfix"></div>
            </div>
            <div class="clearfix"></div>

            <div class="x_content">  

            <!-- search parameters   -->
            <form class="form-default" method="POST" action="<? echo base_url('asset/ocslist'); ?>">
                <div class="item form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12" for="bios_type">Type <span class="required">*</span></label>
                  <div class="col-md-6 col-sm-6 col-xs-12">
                    <select class="select2_single form-control" tabindex="-1" name="bios_type">
                      <?php foreach ($ocstype as $key => $value) { ?>
                        <option value="<? echo $value['bios_type']?>"><? echo $value['bios_type']?></option>}
                      <? } ?>
                    </select>
                  </div>
                </div>    

                <div class="item form-group">
                  <label class="control-label col-md-3 col-sm-3 col-xs-12" for="manufacture">Manufacture </label>
                  <div class="col-md-3">
                    <select class="select2_single form-control" tabindex="1" name="manufacture">
                      <?php foreach ($ocsmanu as $key => $value) { ?>
                        <option value="<? echo $value['smanufacturer']?>"><? echo $value['smanufacturer']?></option>}
                      <? } ?>
                    </select>
                  </div>
                </div>                        
                <div>
                      <button type="button" class="btn btn-info" name="submit">Search</button>  
                       <a href="<? echo base_url('asset/listasset'); ?>" class="btn btn-primary">Master Asset</a> 
                  </div>
                </div>
            </form>

              <table id="datatable-fixed-header" class="table responsive-utilities table-bordered">
                <thead>
                  <tr>
                    <th>Type</th>
                    <th>Device ID</th>                        
                    <th>Manufacture</th>
                    <th>Model</th>
                    <th>Nama</th>
                    <<th>User ID</th>
                    <th>Mac_Address</th>
                    <th>Serial Number</th>                        
                    <th>Asset</th>
                  </tr>
                </thead>

                <tbody>
                  <?php foreach ($ocs as $key => $value) { ?>
                    <tr>
                      <td><?php echo $value['bios_type'];?> </td>
                      <td><?php echo $value['DEVICEID'];?> </td>
                      <td><?php echo $value['SMANUFACTURER'];?> </td>
                      <td><?php echo $value['smodel'];?> </td>
                      <td><?php echo $value['name'];?> </td>
                      <td><?php echo $value['userid'];?> </td>
                      <td><?php echo $value['macaddr'];?> </td>
                      <td><?php echo $value['SSN'];?> </td>
                      <td><a href="<? echo base_url('asset/newassetocs'); ?>/<?php echo $value['macaddr'] ; ?>" class="btn btn-primary">Add Asset</a></td> 
                    </tr>
                  <? } ?>
                </tbody>
              </table>
            </div>
          </div>
        </div>
      </div>
    </div>

1 个答案:

答案 0 :(得分:0)

如何将控制器更改为

public function ocslist()
{

    $data['ocs'] = $this->assetmodel->ocsmodel($this->input->post('bios_type'), $this->input->post('manufacture'))->result_array();
    $data['ocstype'] = $this->assetmodel->getocstype()->result_array();
    $data['ocsmanu'] = $this->assetmodel->getocsmanu()->result_array();
    $data['content'] = 'master/ocs_list';
    $this->load->view('template', $data, FALSE);    
}

因为CI将所有POST数据设置为null(如果它们不存在)

有关详细信息,请查看here

<小时/> 更新(20.07.2016)

根据您的观点尝试将按钮类型更改为类似

的类型
<button type="submit" class="btn btn-info" name="submit">Search</button>