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使用自定义类方法的更多相关文章

  1. (转) ThinkPHP模板自定义标签使用方法

    这篇文章主要介绍了ThinkPHP模板自定义标签使用方法,需要的朋友可以参考下  转之--http://www.jb51.net/article/51584.htm   使用模板标签可以让网站前台开发 ...

  2. ThinkPHP框架 自定义 Empty 方法保护本地信息不被暴露!!!

    在使用ThinkPHP框架开发过程中,在每个Controller文件夹里面都要设置一个空控制器,用来保护本地信息不被泄露(EmptyController.class.php) 此方法很有效的隐藏系统内 ...

  3. Thinkphp的自定义路由(route.php)

    废话:因为thinkphp的默认路由会导致URL特别长,从而会影响搜索引擎优化.所以就衍生了自定义路由,尽量将URL缩短. 这是默认的路由文件: <?php return [ '__patter ...

  4. C#封装程序集自定义类方法注释提示

    一.为什么使用封装程序集: 在很多分布式应用程序开发中,针对每一种功能可能条用的接口不一样,往往习惯将需要被调用的接口,封装成DLL给调用方应用后使用,这样既规范了调用的方式,又避免了调用出现参数请求 ...

  5. 大D实例化model-->调用自定义类方法,大M调用原声model方法

    class ContactsModel extends Model{ public function addxxx(){ } } $conmodel = D('contacts','Model'); ...

  6. thinkphp 伪静态 自定义后缀

    <?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...

  7. thinkphp 自定义标签

    关于标签的个人理解是 拼凑php 字符串 通过eval()来进行,返回数据.过程应该是这样的,在模板中加入 定义标签为<mytag:list></mytag>,那么在mvc 中 ...

  8. (转)ThinkPHP自定义模板标签详解

    转之--http://www.thinkphp.cn/topic/6258.html 模板标签让网站前台开发更加快速和简单,这让本该由程序猿才能完成的工作,现在只要稍懂得HTM的人也能轻易做到,这也就 ...

  9. thinkphp 前台html调用函数 格式化输出

    仅仅是输出变量并不能满足模板输出的需要,内置模板引擎支持对模板变量使用调节器和格式化功能,其实也就是提供函数支持,并支持多个函数同时使用.用于模板标签的函数可以是PHP内置函数或者是用户自定义函数,和 ...

随机推荐

  1. php和java优势对比

    PHP很专一,用于创建动态网页的服务器端的脚本语言.作为一种为Web而特别设计的语言,PHP带来了许多商业机构渴望的特性.   ·学习周期短,比较简单 ·快速的开发时间 ·非常高的性能       这 ...

  2. LeetCode第[29]题(Java):Divide Two Integers

    题目:两整数相除 难度:Medium 题目内容: Given two integers dividend and divisor, divide two integers without using ...

  3. const 函数参数

    void func(int value); 这样的函数,不可以这样子使用: const int value =100; func(value ); 因为func里面可能会对value进行更改,将con ...

  4. java项目生成jar,并在cmd中执行jar

    自己写的jar并使用:============Java项目============Jar包的打包在Eclipse中直接打包,具体步骤: 点击右键>export>jar file>取消 ...

  5. Ajax基础(一)--创建请求

    浏览器创建ajax请求: 1.如果是Firefox.Opera.Safari等高级浏览器,可使用XMLHttpRequest()方式创建一个新的ajax请求对象. 如果是IE浏览器,则使用Active ...

  6. zzuli 2179 最短路

    2179: 紧急营救 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 89  Solved: 9 SubmitStatusWeb Board Descri ...

  7. 转:大数据架构:flume-ng+Kafka+Storm+HDFS 实时系统组合

    虽然比较久,但是这套架构已经很成熟了,记录一下 一般数据流向,从“数据采集--数据接入--流失计算--数据输出/存储”<ignore_js_op> 1).数据采集 负责从各节点上实时采集数 ...

  8. pycharm 设置 默认信息

    在pycharm使用过程中,对于每次新建文件的shebang行和关于代码编写者的一些个人信息快捷填写,使用模板的方式比较方便. 方法如下: 1.打开pycharm,选择File-Settings, 2 ...

  9. mongodb倒排索引

    这周主要都花时间搞mongodb上了,业务场景是上游产出几个城市的全量道路code值,每个城市的数据量大概在100w~200w之间,每条数据对应好几个feature,形如: { code: 0, fe ...

  10. CSS:Tutorial two

    1.CSS Text text color, text align... Text Decoration The text-decoration property is used to set or ...