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.