Php 将值从控制器传递到模型
我需要创建一个通过ajax填充数据的表,代码如下: 查看:Php 将值从控制器传递到模型,php,codeigniter-3,Php,Codeigniter 3,我需要创建一个通过ajax填充数据的表,代码如下: 查看: <form class="form-inline" id="form_filter" method="POST"> <label for="date_from">From </label> <input type="date" name="date_from">
<form class="form-inline" id="form_filter" method="POST">
<label for="date_from">From </label>
<input type="date" name="date_from">
<label for="date_to"> To </label>
<input type="date" name="date_to">
<input type="button" name="btn_view_records" value="Filter Date" class="btn btn-success btn-sm" id="btn_view_records">
</form>
$('#btn_view_records').click(function(){
$.ajax({
type:"POST",
data:$('#form_filter').serialize(),
datataype:"JSON",
url:"<?php echo site_url('pakyaw/get_filtered_data');?>",
success:function(data){
$("#log-list").html(data);
}
});
});
public function get_filtered_data(){
$this->load->library('table');
$this->table->set_heading('Bio Id', 'Log Date', 'Time In', 'Time Out', 'Time Rendendered');
$style = array('table_open' => '<table class="table table-striped table-hover">');
$this->table->set_template($style);
echo $this->table->generate($this->model_pakyaw->get_filtered_data($this->session->userdata('branch_name'), $this->input->post('date_from'), $this->input->post('date_to')));
}
public function get_filtered_data($branch_name, $date_from, $date_to){
$this->output->enable_profiler(TRUE);
$str2="select bio_id as 'bio_id', cast(attendance as date) as 'Log Date', min(attendance) as 'time_in', max(attendance) as 'time_out', timediff(max(attendance), min(attendance)) as 'difference'
FROM delwater_downydb.pakyaw_attendance
WHERE attendance > '".$date_from."'
GROUP BY bio_id, cast(attendance as date)
ORDER BY bio_id, cast(attendance as date) desc;";
$query=$this->db->query($str2);
return $query->result_array();
}
当我点击btn_视图_记录时,它不会过滤结果。我检查过了,我发现从开始的日期没有通过。sql语法正在获取“”值,这就是它未正确筛选的原因。你能告诉我我做错了什么吗。谢谢。您的ajax通话中是否有打字错误
datataype:“JSON”
在ajax调用中应该是dataType:“JSON”
打字错误
datataype:“JSON”,
应该是dataType:“JSON”,
传递分配给post值的变量,或者尝试在模型中打印post值
print_r($_POST); //in model
$from_date = $this->input->post('date_from');//in model
$date_to= $this->input->post('date_to');//in model
$result = $this->table->generate($this->model_pakyaw->get_filtered_data( $from_date, $date_to, $any_other_variable );// in controller
print_r($result);// in controller
传递分配给post值的变量,或尝试在模型中打印post值
print_r($_POST); //in model
$from_date = $this->input->post('date_from');//in model
$date_to= $this->input->post('date_to');//in model
$result = $this->table->generate($this->model_pakyaw->get_filtered_data( $from_date, $date_to, $any_other_variable );// in controller
print_r($result);// in controller
代码看起来没什么问题。您能否显示
var\u dump($\u POST)
?我如何实现它?抱歉,基本上是PHP新手。当我执行“print_r($\u POST);die();”时,就是这样。。。。。“Array()”表示您的表单没有将数据发布到正确的URL。请检查您的帖子URL。代码看起来没有问题。您能否显示var\u dump($\u POST)
?我如何实现它?抱歉,基本上是PHP新手。当我执行“print_r($\u POST);die();”时,就是这样。。。。。“Array()”表示您的表单没有将数据发布到正确的URL。请检查您的帖子URL。