To put in simple words I want status1 to go to ajaxleadsreport controller
A bit more complex explanation:
I have 2 view classes called indexreport and ajaxleadsreport. ajaxleadsreport fetches all the data and displays it. Now I have a GET variable that is being passed to indexreport which I want to be able to pass it to ajaxleadsreport to filter the current data according to the GET variable that has been passed.
Controller Class:
public function listsreport($slug='')
{
$status1 = $this->input->get('status');
print_r($status1);
$main['content']=$this->load->view('crm/leads/indexreport',$content,true);
}
public function ajaxleadsreport($p='')
{
$output = array( 'html'=>$this->load->view('crm/leads/ajaxleadsreport',$content, true));
echo json_encode($output);
}
indexreport View Class:
<?php
$i=$return=$uriseg;
$post=$this->input->post(); $sess=$this->session->userdata();
$post = $post?$post:$sess;
?>
<div>
...
</div>
$(document).ready(function (){
getleads();
});
function getleads(p){
$.ajax({
type: "post",dataType:"json",async:false,cache:true,
url: "<?php echo site_url('leads/ajaxleadsreport'); ?>" ( parseInt(p)>0?'/' p:''),
data: $('#objlistform').serialize(),
success: function(e){$('#leadswrap').hide().html(e.html).fadeIn('slow');}
}); return false;
}
ajaxleadsreport View class:
<?php
$sess=$this->session->userdata();
$status1 = $this->input->get('status');
// This is where I'm trying to put my GET value of status for filtering but it gives NULL.
$post = array('fstatus'=> $status,'fpriority'=> $sessn['fpriority']);
$postd = json_encode(array_filter($post));
?>
...
<script>
$(document).ready(function() {
function sendreq(){
setpostdatas();cleartable();getleads();
}
var slug = '<?php echo $slug?>';
var postd = '<?php echo $postd; ?>';
$('#item-list').DataTable({
"processing": true,
"stateSave": true,
"serverSide": true,
"ordering": false,
"ajax": {
url: "<?php echo site_url(); ?>leads/loadLeads",
data: {slug: slug, postdata: postd},
type : 'POST',
"dataSrc": function ( d ) {
d.myKey = "myValue";
if(d.recordsTotal == 0 || d.data == null){
$("#item-list_info").text("No records found");
}
return d.data;
}
},
'columns': [
{"data": "id", "id": "id"},
{"data": "lead_status", "lead_status": "lead_status"},
{"data": "priority", "priority": "priority"},
]
});
As you can see in the code above, I've tried $status1 = $this->input->get('status');
in ajaxleadsreport View class but the output for that is NULL, since the GET value is passed in my indexreport view class. When I do a print_r($status1)
in indexreport controller it gives the right output, but NULL in ajaxleadsreport controller.
So basically now I need a way to pass this GET value to ajaxleadsreport controller.
CodePudding user response:
In the controller class declare the variable: protected $status1; public function listsreport() { $this->status1 = $this->input->get('status'); [...] Then you can access $this->status1 from any function that is invoked after.
CodePudding user response:
You can use flashdata here:
Set your status to flashdata then get it out in ajaxleadsreport like this: (flashdata only exist once on next request)
$this->session->set_flashdata('status', $status1);
In ajaxleadsreport:
$this->session->flashdata('status');