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内置函数或者是用户自定义函数,和 ...
随机推荐
- centos下使用fdisk扩展分区容量大小
硬盘空间为20G,VMware增加磁盘大小,需要再增加10G空间 扩展完后,重启系统,再次使用fdisk -l查看,会发现硬盘空间变大了: 重新创建分区,调整分区信息 本次实验主要对/dev/sda4 ...
- yii2:属性
yii2:属性 在 PHP 中,类的成员变量也被称为属性(properties). 以Foo.php类文件为例: 继承yii\base\Object类(基于类内的 getter 和 setter(读取 ...
- 数据库oracle(PGA+SGA分配机制)
一.名词解释 (1)SGA:System Global Area是Oracle Instance的基本组成部分,在实例启动时分配;系统全局域SGA主要由三部分构成:共享池.数据缓冲区.日志缓冲区. ( ...
- Nginx 常用配置模板
user root root; worker_processes auto; worker_rlimit_nofile 51200; events { use epoll; worker_connec ...
- pdb 源码索引符号服务器创建过程
pdb是调试程序必不可少的东西,它保存着一个exe或dll的调试信息,对pdb进行源码索引可以快速找到软件对应该版本的代码,本文以subversion版本控制服务器进行介绍 一.需要安装的软件 win ...
- 由PostgreSQL的区域与字符集说起(转)
转自:http://blog.chinaunix.net/uid-354915-id-3502551.html 由PostgreSQL的区域与字符集说起 一.PostgreSQL的区域区域属性有以下几 ...
- H264提供了哪些帧内预测?
H.264/AVC 提供了四种帧内预测方式:4x4 亮度块的帧内预测(Intra_4x4).16x16 亮度块的帧内预测(Intra_16x16).8x8 色度块的帧内预测(Intra_chroma) ...
- [置顶]
Android 关于BottomDialogSheet 与Layout擦出爱的火花?
今天上班做那个类似于ios拍照的那种效果图 就是个垂直布局然后里面textview+分割线+textview+button 当然也可以用button+分割线+button 方法有很多,选择适合自己的就 ...
- Android 进阶8:进程通信之 Binder 机制浅析
读完本文你将了解: IBinder Binder Binder 通信机制 Binder 驱动 Service Manager Binder 机制跨进程通信流程 Binder 机制的优点 总结 Than ...
- 7.usr下重要目录和文件详解
1./usr下重要目录和文件详解: /usr(存放用户安装的应用软件目录,如MySQL,Apache,这是一个非常重要的目录,类似于Windows下的Program Files目录,用户的很多应用程序 ...