dongzhan0624 2011-10-10 05:11
浏览 54
已采纳

在jquery post之后调用另一个php函数

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() {
  //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

  • 写回答

2条回答 默认 最新

  • du4010 2011-10-10 05:27
    关注

    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();

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程