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模板自定义标签使用方法,需要的朋友可以参考下 转之--http://www.jb51.net/article/51584.htm 使用模板标签可以让网站前台开发 ...
- ThinkPHP框架 自定义 Empty 方法保护本地信息不被暴露!!!
在使用ThinkPHP框架开发过程中,在每个Controller文件夹里面都要设置一个空控制器,用来保护本地信息不被泄露(EmptyController.class.php) 此方法很有效的隐藏系统内 ...
- Thinkphp的自定义路由(route.php)
废话:因为thinkphp的默认路由会导致URL特别长,从而会影响搜索引擎优化.所以就衍生了自定义路由,尽量将URL缩短. 这是默认的路由文件: <?php return [ '__patter ...
- C#封装程序集自定义类方法注释提示
一.为什么使用封装程序集: 在很多分布式应用程序开发中,针对每一种功能可能条用的接口不一样,往往习惯将需要被调用的接口,封装成DLL给调用方应用后使用,这样既规范了调用的方式,又避免了调用出现参数请求 ...
- 大D实例化model-->调用自定义类方法,大M调用原声model方法
class ContactsModel extends Model{ public function addxxx(){ } } $conmodel = D('contacts','Model'); ...
- thinkphp 伪静态 自定义后缀
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.we ...
- thinkphp 自定义标签
关于标签的个人理解是 拼凑php 字符串 通过eval()来进行,返回数据.过程应该是这样的,在模板中加入 定义标签为<mytag:list></mytag>,那么在mvc 中 ...
- (转)ThinkPHP自定义模板标签详解
转之--http://www.thinkphp.cn/topic/6258.html 模板标签让网站前台开发更加快速和简单,这让本该由程序猿才能完成的工作,现在只要稍懂得HTM的人也能轻易做到,这也就 ...
- thinkphp 前台html调用函数 格式化输出
仅仅是输出变量并不能满足模板输出的需要,内置模板引擎支持对模板变量使用调节器和格式化功能,其实也就是提供函数支持,并支持多个函数同时使用.用于模板标签的函数可以是PHP内置函数或者是用户自定义函数,和 ...
随机推荐
- MVVM架构说明1
MVVM是Model-View-ViewModel的简写.微软的WPF带来了新的技术体验,如Sliverlight.音频.视频.3D.动画……,这导致了软件UI层更加细节化.可定制化.同时,在技术层面 ...
- Django进阶Admin篇 - admin基本配置
django admin 是django自带的一个后台app,提供了后台的管理功能. 基础知识点: 一.认识ModelAdmin 管理界面的定制类,如需扩展特定的model界面,需要从该类继承 二.注 ...
- poj3181 背包+大数
http://poj.org/problem?id=3181 Dollar Dayz Time Limit: 1000MS Memory Limit: 65536K Total Submissio ...
- 26-THREE.JS 虚线绘制线框样式几何图形的材质
<!DOCTYPE html> <html> <head> <title></title> <script src="htt ...
- LeetCode OJ:Maximum Subarray(子数组最大值)
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- PostBack IsPostBack
这涉及到aspx的页面回传机制的基础知识 postback是回传 即页面在首次加载后向服务器提交数据,然后服务器把处理好的数据传递到客户端并显示出来,就叫postback, ispostback只是一 ...
- DRF 的视图,路由和渲染器
DRF 的视图,路由和渲染器 1 视图 简单的增删改查 : ModelViewSet; 复杂的操作使用APIView 和 GenericViewSet APIView(View) class Home ...
- CollectionUtils工具类使用指南
CollectionUtils提供很多对集合的操作方法,常用的方法如下:(参考文章:http://www.open-open.com/code/view/1420470842125) import o ...
- nodejs express project
user root install express npm install express -g install express... npm install express-generator -g ...
- 神奇的TextField(1)
先看一大段测试代码,每个小方法的注释行是输出结果. private var text_content:TextField; private function textFieldDemo():void{ ...