Calling other function in the same controller?

前端 未结 2 1891
一整个雨季
一整个雨季 2020-12-24 10:12

I\'ve this controller, and the function read($q) return error Call to undefined function sendRequest()



        
相关标签:
2条回答
  • 2020-12-24 10:43

    Try:

    return $this->sendRequest($uri);
    

    Since PHP is not a pure Object-Orieneted language, it interprets sendRequest() as an attempt to invoke a globally defined function (just like nl2br() for example), but since your function is part of a class ('InstagramController'), you need to use $this to point the interpreter in the right direction.

    0 讨论(0)
  • 2020-12-24 10:45

    Yes. Problem is in wrong notation. Use:

    $this->sendRequest($uri)
    

    Instead. Or

    self::staticMethod()
    

    for static methods. Also read this for getting idea of OOP - http://www.php.net/manual/en/language.oop5.basic.php

    0 讨论(0)
提交回复
热议问题