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


Search submit button not working in 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>

把你的控制器换成之类的东西怎么样

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

有关更多信息,请查看此处


更新(20.07.2016)

根据你的看法,试着把按钮类型改成类似的东西

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