• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to set and access global variable through controller functions?

#5
You don't need a hidden field. You can "inject" a php variable into Javascript code.

Example:
Code:
$('#some_button').click(function(){
  var url = "<?= site_url('groups/anotherfunction/' . $page_id);?>";
  $.post( url )
  .done(function(data) {
     $('#some_element').html(data);
  });
});

In the controller, load the view and put it in a variable:
PHP Code:
$dynamic_html $this->load->view('group/anotherFunction',NULL,TRUE);
echo 
$dynamic_html
The 3rd argument of $this->load->view() will return the value.
The echo in the controller function will return the result to the Ajax call.
Maybe loading the view as usual will work as well, but I didn't test that.
Reply


Messages In This Thread
RE: How to set and access global variable through controller functions? - by Wouter60 - 09-15-2019, 03:47 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.