如何在后台执行codeigniter控制器方法

时间:2015-08-13 13:20:10

标签: php codeigniter

我有一个codeigniter的控制器功能,可以从gmail中获取邮件。

这需要花费大量时间,所以我需要在后台执行特定的控制器功能,这样用户无需等到所有邮件都被提取。

1 个答案:

答案 0 :(得分:0)

Ajax Jquery Way

JS:

$.ajax({
    url   : "index.php?/MyController/myMethod",
    async : true //change this to false if you hate your users and want them to wait 
}).done(function() {
    alert("EMAIL IS READY! USER DIDN'T WAIT")
});

PHP:

class MyController extends CI_Controller{

      function myMethod(){
          //do your email stuff
      }

      //if codgeIgniter V2
      function myMethod_get(){
          //do your email stuff
      }

}