我搜索了很多但找不到问题的答案。 set_value()
表单方法无法使用GET
函数,而POST
表单方法正在使用MySQL
。我正在尝试从GET
获取行,我想使用<?=form_open('employee_registration/search_employee', ['role'=>'form','method'=>'GET']);?>
<div class="row">
<div class="col-sm-3">
<div class="form-group">
<label>R. No.<span class="required">*</span></label>
<input class="form-control" placeholder="R. No." name="srch_r_no" id="srch_r_no" value="<?=set_value('srch_r_no');?>">
</div>
</div>
<div class="col-sm-3">
<div class="form-group">
<label>Name<span class="required">*</span></label>
<input class="form-control" placeholder="Name" name="srch_e_name" id="srch_e_name" value="<?=set_value('srch_e_name');?>">
</div>
</div>
</div>
<button type="submit" class="btn btn-primary" name="srch_btn">Search <span class="fa fa-search"></span></button>
<?=form_close();?>
方法。有人可以帮忙吗?
视图:
public function search_employee()
{
$get = $this->input->get();
unset($get['srch_btn']);
$table = $this->md_emp_reg->search_employee($get);
$this->index('view',$table);
}
控制器:
public function search_employee($get)
{
$parameters = $this->filter_values($get,"search");
$query = "CALL `sp_select_employee_details`(".$parameters.");";
$grid = $this->table($query);
return $grid;
}
public function filter_values($arr,$type)
{
$arr_keys = array_keys($arr);
$filtered_values = "";
for ($i=0; $i < count($arr); $i++)
{
if ($arr[$arr_keys[$i]] == "" && $type == "search")
{
$arr[$arr_keys[$i]] = "";
}
elseif($arr[$arr_keys[$i]] == "" && $type != "search")
{
$arr[$arr_keys[$i]] = NULL;
}
$filtered_values .= $this->db->escape($arr[$arr_keys[$i]]).",";
}
return rtrim($filtered_values,',');
}
public function table($query)
{
$result = $this->db->query($query);
$r_arr = $result->result_array();
$result_fields_name = $result->list_fields();
$result_num_fields = $result->num_fields();
$result_num_rows = $result->num_rows();
$table = '<table width="100%" class="table table-condensed table-striped table-bordered table-hover" id="dataTables-example"><thead><tr>';
for ($a=0; $a < $result_num_fields; $a++)
{
$table .= "<th>".$result_fields_name[$a]."</th>";
}
$table .="</tr></thead><tbody>";
for ($i=0; $i < count($r_arr) ; $i++)
{
$table .= "<tr>";
for ($j=0; $j < $result_num_fields ; $j++)
{
$table .= "<td>".$r_arr[$i][$result_fields_name[$j]]."</td>";
}
$table .= "</tr>";
}
$table .="</tbody></table>";
$this->db->close();
return $table;
}
模型:
colModel: $scope.colModelValue
答案 0 :(得分:0)
这是功能:
function set_value($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = (isset($CI->form_validation) && is_object($CI->form_validation) && $CI->form_validation->has_rule($field))
? $CI->form_validation->set_value($field, $default)
: $CI->input->post($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
删除form_validation
逻辑,因为它对我们没用,我们得到:
function set_value($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = $CI->input->post($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
交换帖子我们可以创建自己的帮助器set_value_get()
,将它保存在帮助器中,加载帮助器.etc。:
function set_value_get($field, $default = '', $html_escape = TRUE)
{
$CI =& get_instance();
$value = $CI->input->get($field, FALSE);
isset($value) OR $value = $default;
return ($html_escape) ? html_escape($value) : $value;
}
用法与set_value
相同。