最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

thinkPHP自定義類實(shí)現(xiàn)方法詳解

 更新時(shí)間:2016年11月30日 11:11:59   作者:牛逼的霍嘯林  
這篇文章主要介紹了thinkPHP自定義類實(shí)現(xiàn)方法,結(jié)合實(shí)例形式分析了thinkPHP自定義模型類的定義與使用技巧,需要的朋友可以參考下

本文實(shí)例講述了thinkPHP自定義類實(shí)現(xiàn)方法。分享給大家供大家參考,具體如下:

1.通過(guò)Model調(diào)用

<?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,否則會(huì)因?yàn)楸聿淮嬖诙鴪?bào)錯(cuò)。

調(diào)用,

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

調(diào)用確實(shí)方便,但是總感覺有點(diǎn)不合理。這個(gè)D畢竟是操作數(shù)據(jù)庫(kù)的。

2.通過(guò)引入類實(shí)現(xiàn),把類放到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));
  }
}
?>

調(diào)用

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

配置一下,自動(dòng)加載

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

這樣調(diào)用就方便了不管Api文件夾下有多少類,都會(huì)自動(dòng)加載,不需要單個(gè)引用import("@.ORG.Api.Integral")了。

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

新化县| 应城市| 阳山县| 广宁县| 铁岭市| 都昌县| 保康县| 朝阳市| 永福县| 报价| 大姚县| 镶黄旗| 佳木斯市| 台东县| 遂川县| 集安市| 双城市| 千阳县| 公主岭市| 合作市| 巴马| 锦州市| 佛山市| 黄大仙区| 交城县| 满城县| 新沂市| 珲春市| 荣成市| 建湖县| 马边| 大埔县| 宁海县| 天镇县| 安泽县| 孝昌县| 屯留县| 黄山市| 庆城县| 高台县| 东明县|