Thinkphp introduces a public class. in other methods, thinkphp does not need to be instantiated to call thinkphp to introduce a public class, and thinkphp does not need to be instantiated to call other methods.
Text ("hello, I'm wechat")-> reply (); // The class instantiated above cannot be called here. // How can I perform this operation?} public function test () {$ weObj-> text ("hello, I'm wechat")-> reply (); // The class instantiated above cannot be called here. // How can I operate it }}
Reply to discussion (solution)
This is a class that creates a public variable ....
How to create it? I have tried it and it seems that it cannot be inherited.
Class WuyeController extends CheckController {protected $ wechat; protected function _ initialize () {$ token = 'weixin '; // The TOKEN $ this-> wechat = new Wechat ($ token);} public function index () {$ this-> weObj-> text ("hello, i'm wechat ")-> reply ();} public function test () {$ this-> weObj-> text (" hello, I'm wechat ") -> reply ();}}
Thanks for your reply, but it still does not work. The message "Call to a member function text () on a non-object" is displayed.
That is, the instance is not instantiated successfully.
The class library I use is this
Https://github.com/dodgepudding/wechat-php-sdk
Where is your class library file? import the file and try again.
The class library is correct. I can correctly reference it in _ initialize, but it cannot be referenced in other methods.
Change the protected of the initialization method to public, and write it on the third floor.
CheckController class definition not found in wechat-php-sdk-master project
The _ initialize method definition is not found.
Can you confirm that _ initialize is executed during class instantiation?
As identity authentication, token is usually issued dynamically. can you write it to death?
_ Initialize can be used directly.
The token is only a parameter of the class. it can be used without adding any token, but why cannot it be used in tp?
I saw a wechat and a weobj...
WeObj = new Wechat ($ token);} public function index () {$ this-> weObj-> text ("hello, I'm wechat")-> reply (); // The class instantiated above cannot be called here. // How can I perform this operation?} public function test () {$ this-> weObj-> text ("hello, i'm wechat ")-> reply (); // The class instantiated above cannot be called here // how to operate it }}