Implementation of thinkPHP custom classes _ php instances

Source: Internet
Author: User
This article mainly introduces thinkPHP custom class implementation method, and analyzes the definition and usage skills of thinkPHP custom model class based on the instance form, for more information about thinkPHP custom class implementation methods, see the example in this article. We will share this with you for your reference. The details are as follows:

1. call with Model

<? Php/*** integral model api interface */class ApiModel {private $ url = 'http: // js.yunlutong.com/Customer/Interface'; public function test () {$ post_data ['action'] = 'sadf'; $ post_data ['callback'] = '? '; $ Res = request_post ($ this-> url, $ post_data); $ firstChar = substr ($ res, 0, 1); if ($ firstChar = '? ') {$ Res = substr ($ res, 2); $ res = substr ($ res, 0, strlen ($ res)-1 );} elseif ($ firstChar = '(') {$ res = substr ($ res, 1); $ res = substr ($ res, 0, strlen ($ res) -1);} dump (json_decode ($ res, true ));}}

The Model is not inherited; otherwise, an error is returned because the table does not exist.

Call,

$Api = D('Api');$Api->test();

The call is really convenient, but it seems a bit unreasonable. After all, this D is used to operate databases.

2. put the class under ORG by introducing the class implementation

<?phpclass Integral{  private $url = 'http://js.yunlutong.com/Customer/Interface';  public function test() {    $post_data['action']    = 'sadf';    $post_data['callback']   = '?';    $res = request_post($this->url, $post_data);    $firstChar = substr($res,0,1);    if ($firstChar =='?') {      $res = substr($res,2);      $res = substr($res,0,strlen($res)-1);    } elseif($firstChar == '(') {      $res = substr($res,1);      $res = substr($res,0,strlen($res)-1);    }    dump($res);    dump(json_decode($res,true));  }}?>

Call

import("@.ORG.Api.Integral");$integralApi = new Integral();$integralApi->test();

Configure and automatically load

'APP_AUTOLOAD_PATH'   => '@.ORG,@.ORG.Api',

This makes it easy to automatically load the Api regardless of the number of classes in the Api folder. you do not need to reference a single import ("@. ORG. Api. Integral.

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.