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. 门户diy实现翻页功能的方法

    1.打开 \source\class\block\portal\block_article.php 文件 找到 function getdata($style, $parameter) 修改为 fun ...

  2. Spring MVC + Java 多文件上传及多文件中转上传

    1.html内容 <div> <form method="post" action="/Cyberspace/main/informationBatch ...

  3. LeetCode OJ:Roman to Integer(转换罗马字符到整数)

    Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 t ...

  4. elasticsearch聚合案例--分组、求最大值再求最大值的均值

    一.需求 A.B.C代表3个用户,第二列代表各自的得分,求A.B.C的最好成绩以及A.B.C最好成绩的均值 A 10 A 11 A 13 B 11 B 11 B 12 C 10 C 10 C 11 C ...

  5. 【MFC】如何在MFC创建的程序中更改主窗口的属性 与 父窗口 WS_CLIPCHILDREN 样式 对子窗口刷新的影响 与 窗体区域绘制问题WS_CLIPCHILDREN与WS_CLIPSIBLINGS

    如何在MFC创建的程序中更改主窗口的属性 摘自:http://blog.sina.com.cn/s/blog_4bebc4830100aq1m.html 在MFC创建的单文档界面中: (基于对话框的, ...

  6. Android 拍照或从相册取图片并裁剪

    在Android中,Intent触发Camera程序,拍好照片后,将会返回数据,但是考虑到内存问题,Camera不会将全尺寸的图像返回给调用的Activity,一般情况下,有可能返回的是缩略图,比如1 ...

  7. Spring、Spring MVC、Struts2优缺点整理

    Spring 及其优点 大部分项目都少不了Spring的身影,为什么大家对他如此青睐,而且对他的追捧丝毫没有减退之势呢 Spring是什么: Spring是一个轻量级的DI和AOP容器框架. 说它轻量 ...

  8. 【3】SpringMVC的Controller

    1SpringMvc的Controller是线程安全的吗? (1)由于是单例,tomcat的多线程环境访问,属性必须是不可变的,如果可变,会产生脏数据,线程不安全 2Spring的事务管理 (1)ao ...

  9. LA4728 Squares

    题意 PDF 分析 就是求凸包点集的直径. 当然选择旋转卡壳. 然后是实现上的技巧: 当Area(p[u], p[u+1], p[v+1]) <= Area(p[u], p[u+1], p[v] ...

  10. openid和unionId的区别

    转:http://blog.csdn.net/wo849533144long/article/details/50194623