[英]Pass php variable from view to controller to model using codeigniter
I want to pass php variable from view to controller then in my model using codeigniter. 我想将PHP变量从视图传递到控制器,然后在我的模型中使用codeigniter。
The problem is that the variable is not getting passed to the controller. 问题在于该变量未传递到控制器。
Below is my View and Controller code. 下面是我的视图和控制器代码。
Please note that the variable is got onload not through form inputs. 请注意,变量不是通过表单输入加载的。
This is my View 这是我的看法
<script> $(document).ready(function (){ //fill data fillgrid(); function fillgrid(){ $("#loader").show(); $.ajax({ var subcategory_id = <?php echo $sub_id; ?>, url:'<?php echo base_url() ?>Shop/get_products_in_sub_subcategory/'+subcategory_id, type:'GET' }).done(function (data){ $("#fillgrid").html(data); $("#loader").hide(); }); } }); </script>
Controller 控制者
public function get_products_in_sub_subcategory(){ $subcategory_id = $this->uri->segment(3); $this->Account_model->get_products_in_sub_subcategory($subcategory_id); }
Hope this will help you : 希望这个能对您有所帮助 :
Put your variable subcategory_id
outside the ajax like this : 像这样将变量
subcategory_id
放在ajax之外:
$(document).ready(function(e){
fillgrid();
function fillgrid()
{
var subcategory_id = '<?php echo $sub_id; ?>';
$("#loader").show();
$.ajax({
url:'<?=base_url("Shop/get_products_in_sub_subcategory/");?>'+subcategory_id,
type:'GET'
}).done(function (data){
alert(data);
console.log(data)
$("#fillgrid").html(data);
$("#loader").hide();
});
}
});
And your method get_products_in_sub_subcategory
should be like this : 您的方法
get_products_in_sub_subcategory
应该像这样:
public function get_products_in_sub_subcategory($subcategory_id)
{
echo $subcategory_id;
//$this->Account_model->get_products_in_sub_subcategory($subcategory_id);
exit;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.