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内置函数或者是用户自定义函数,和 ...
随机推荐
- 栈的基本操作--java实现
package com.wyl.linklist; /** * 栈的定义及相关操作 * 用数组实现栈 * 栈是一个线性表,不过进栈和出栈操作在表尾操作 * @author wyl * */ publi ...
- ASP.NET动态创建数据库和表
using System; using System.Collections.Generic; using System.Data; using System.Data.SqlClient; usin ...
- Selenium with Python 006 - 操作浏览器
#!/usr/bin/env python # -*- coding: utf-8 -*- from selenium import webdriver import time driver = we ...
- jenkins 环境搭建与入门示例
环境说明: 1.win7 2.tomcat 9.0.0.M17 3.jenkins 2.32.2.war jenkins 环境搭建 1.下载jenkins部署包 https://jenkins.io/ ...
- Linux:配置Linux网络和克隆虚拟机并更改配置
Linux学习笔记1:配置Linux网络和克隆虚拟机并更改配置 一.配置Linux网络 在安装Linux的时候,一定要保证你的物理网络的IP是手动设置的,要不然会在Linux设置IP连通网络的时候 ...
- MySQL 5.6 二进制包安装配置多实例方法
MySQL支持一台机器上启动多个实例,如果你的机器性能很好的话,启动多个实例将最大化利用你的服务器硬件资源. MySQL多实例一般有两种配置方法: 1.官方推荐的mysqld_multi方式,多个实例 ...
- requests beautifulsoup
requests Python标准库中提供了:urllib.urllib2.httplib等模块以供Http请求,但是,它的 API 太渣了.它是为另一个时代.另一个互联网所创建的.它需要巨量的工作, ...
- Node net模块与http模块一些研究
这周遇到一个有意思的需求,端上同学希望通过 socket 传送表单数据(包含文件内容)到 node 端,根据表单里的文件名.手机号等信息将文件数据保存下来.于是我这样写了一下--socket_serv ...
- Selenium2+Python自动化学习笔记(第1天)
参考[http://blog.csdn.net/henni_719/article/details/51096531]大神写的笔记,多谢大神共享. 哈哈,今天又找到一位大神写的Selenium2+Py ...
- WMS专业名词解释
1.摘果:按照单一客户上订单的内容进行拣选货品(即去货位上拣货),拣选完成后即可直接进行质检.包装. 2.播种:将多个客户订单上的货品进行汇总,然后对这些货品进行拣选.拣选完成后,再区分出每一个客户的 ...