Thinkphp introduces a public class and how to call thinkphp without instantiating it in other methods

Source: Internet
Author: User
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 }}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.