Thinkphp introduces a public class that does not need to instantiate calls in other methods

Source: Internet
Author: User
Thinkphp introduces a public class that does not need to instantiate calls in other methods

 
  Text ("Hello, I ' m WeChat")->reply (); It is not possible to invoke the above instantiated class//operation to use} public    function test () {$weObj->text ("Hello, I ' m WeChat")->reply (); You cannot invoke the class that you instantiated above//How to do this in order to use    }}





Reply to discussion (solution)

This is a class that creates a public variable ....

How to create it, I've tried it like I can't inherit

Class Wuyecontroller extends Checkcontroller {   protected $wechat;   protected function _initialize () {         $token = ' weixin ';//tokens         $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 ();}    }

Thank you for the reply, but still no, prompt to a member function text () on a non-object

Which is that there is no instantiation of success

The class library I'm using is this.

Https://github.com/dodgepudding/wechat-php-sdk

Where to put your class library files, you need to introduce files and try again, import or vendor.

The class library is correct and I can refer to it correctly in _initialize, but in other ways it cannot be referenced

Change the protected of the initialization method to public, then write on the third floor.

The Checkcontroller class definition was not found in the Wechat-php-sdk-master project
And I didn't find the definition of the _initialize method.

Can you confirm that _initialize was executed when the class was instantiated?

Token as the identity authentication, usually is the dynamic release, you write Dead can?

This class can be used directly in the _initialize.
Token is just a parameter of the class, no plus, but why can't 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 ();         It is not possible to invoke the above instantiated class         //How to use the     } public          function test () {         $this->weobj->text ("Hello, I ' m WeChat ")->reply ();         You cannot invoke the class that you instantiated above         //How to do this in order to use     }}
  • 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.