开发者

calling another php function after jquery post

开发者 https://www.devze.com 2023-04-11 16:48 出处:网络
I am performing the jquery POST correctly, however I would like to call another PHP function inside the controller. EDIT The code below works fine....I\'m just an idiot. Someone close this please.

I am performing the jquery POST correctly, however I would like to call another PHP function inside the controller. EDIT The code below works fine....I'm just an idiot. Someone close this please.

Here is the setup:

class controller extends CI_Controller {

  function con1() {
开发者_如何学Python  //retrieve post variable
  $this->con2()
  }

  function con2() {
  //do something
  $this->my_model->get_results() //fails
  }

}

Jquery POSTS to con1, however it will fail when i do $this->con2(). Is there anyway I can get this to work? Also, is it possible to call a model once jquery posts the data?

Thanks


It's not really clear what you aren't able to do, but why are you juggling with controller's methods, when model are done just for that? The purpose of a Model is being something re-usable, so why don't you call it right in con1() method?

class Controller extends CI_Controller {

  function con1() {
  $this->load->model('my_model');
  //retrieve post variable
  echo $this->my_model->get_results(); 
  }
}

Also, post variable are available to Models also, if you want to grab their values there. If you expand your answer with further details I'll edit and update my question, so far it's just a bit of a guessing on what's wrong. The code I showed should work, provided the get_result() method actually returns something (which you need to echo out).

If by "how do I call a function within a model" means how you call a model's method inside another model's method, well, it works like any php class method's call, $this->other_method();


Haven't used codeigniter but I suspect redirecting to con2 within con1 with the post array would fix the issue.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号