dpo15099 2016-11-21 22:04
浏览 66

Nusoap访问$ this inside方法 - 在不在对象上下文中时使用$ this

I have a nusoap class, with some methods defined in the constructor. The problem I'm having however, is calling a method either from a model I loaded or a method defined in the same class out of the constructor. The error I get is "Using $this when not in object context". None of the methods are static, so I'm not sure why it's having trouble accessing this. For reference, here is an example of what I'm trying to do.

edit: This is my first time working with nusoap, and the methods were defined in the constructor in all the examples I saw. If the methods do not need to be defined in the constructor, where do I define them?

class MySoapServer extends CI_Controller {
    function __construct() { 
       parent::__construct();
       //where I'm loading all my models and libraries, 
       //creating a new instance of soap server
       //and registering all my methods


       function myFunction() {
            $this->testFunction() //this is where it errors out
       }
    }

    function testFunction() {
        return true;
    }
}
  • 写回答

2条回答 默认 最新

  • donglv6960 2016-11-21 22:20
    关注

    Your function is in another function, it should look like:

    class MySoapServer extends CI_Controller {
        function __construct() { 
           parent::__construct();
           //where I'm loading all my models and libraries, 
           //creating a new instance of soap server
           //and registering all my methods
    
    
        }
        function myFunction() {
            $this->testFunction() //this is where it errors out
        }
        function testFunction() {
            return true;
        }
    }
    

    What you seem to be trying to do is run testFunction() in the constructor? If that's the case then myFunction() isn't needed and you just need to add $this->testFunction() at the end of the constructor.

    Like this:

    class MySoapServer extends CI_Controller {
            function __construct() { 
               parent::__construct();
               //where I'm loading all my models and libraries, 
               //creating a new instance of soap server
               //and registering all my methods
               $this->testFunction();
            }
            function testFunction() {
                return true;
            }
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向