This article describes the implementation method of Thinkphp custom class. Share to everyone for your reference, as follows:
1. Call through model
<?php/** * Integration 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));} }
Does not inherit the model, otherwise it will be error because the table does not exist.
Call
$Api = D (' Api '); $Api->test ();
The call is really convenient, but the overall feeling is a little unreasonable. This d is, after all, an operational database.
2. By introducing the class implementation, put the class into the Org
<?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, automatically load
' App_autoload_path ' = ' @.org,@.org.api ',
This makes the invocation convenient, regardless of the number of classes in the Api folder, will automatically load, do not need a single reference import ("@.org.api.integral").
More interested in thinkphp related content readers can view this site topic: "thinkphp Introductory Tutorial", "thinkphp Template Operation Skills Summary", "thinkphp Common Methods Summary", "CodeIgniter Getting Started Tutorial", "CI ( CodeIgniter) Framework Advanced Tutorial, "Smarty Template Primer Basic Tutorial" and "PHP template technology Summary."
It is hoped that this article is helpful to the PHP program design based on thinkphp framework.