excel數字變成了小數點+e+10是什么原因
1216
2023-11-19
本文實例講述了thinkPHP自定義類實現方法。分享給大家供大家參考,具體如下:
1.通過Model調用
<?php /** * 積分模型 api接口 */ 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)); } }
沒有繼承Model,否則會因為表不存在而報錯。
調用,
$Api = D('Api'); $Api->test();
調用確實方便,但是總感覺有點不合理。這個D畢竟是操作數據庫的。
2.通過引入類實現,把類放到ORG下
<?php class 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)); } } ?>
調用
import("@.ORG.Api.Integral"); $integralApi = new Integral(); $integralApi->test();
配置一下,自動加載
'APP_AUTOLOAD_PATH' => '@.ORG,@.ORG.Api',
這樣調用就方便了不管Api文件夾下有多少類,都會自動加載,不需要單個引用import("@.ORG.Api.Integral")了。
更多關于thinkPHP相關內容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結》、《ThinkPHP常用方法總結》、《codeigniter入門教程》、《CI(CodeIgniter)框架進階教程》、《smarty模板入門基礎教程》及《PHP模板技術總結》。
希望本文所述對大家基于ThinkPHP框架的PHP程序設計有所幫助。
#免責聲明#
本站[綠夏技術導航]提供的一切軟件、教程和內容信息僅限用于學習和研究目的;不得將上述內容用于商業或者非法用途,否則,一切后果請用戶自負。本站信息來自網絡收集整理,版權爭議與本站無關。您必須在下載后的24個小時之內,從您的電腦或手機中徹底刪除上述內容。如果您喜歡該程序或內容,請支持正版,購買注冊,得到更好的正版服務。我們非常重視版權問題,如有侵權請郵件[admin@lxwl520.com]與我們聯系進行刪除處理。敬請諒解!