7d 根目录

├─Application 应用目录

│ ├─Common 公共模块

│ │ ├─Common 公共函数文件目录

│ │ │ ├─index.html

│ │ ├─Config 配置文件目录

│ │ │ ├─config.php

│ │ │ ├─index.html

│ ├─Home Home模块

│ ├─Runtime 运行时的目录

├─Public 资源文件目录

├─ThinkPHP 框架目录

└─index.php 入口文件

1. 默认公共函数文件

在ThinkPHP3.2.3中,默认的公共函数文件位于公共模块./Application/Common下,访问所有的模块之前都会首先加载公共模块下面的配置文件(Conf/config.php)和公共函数文件(Common/function.php),即默认的公共函数文件为./Application/Common/Common/function.php。

不过第一次访问入口文件生成的目录结构中,并没有生成公共函数文件(Common/function.php)。因此,需要自己手动创建./Application/Common/Common/function.php这个文件。

示例:

在./Application/Common/Common下新建function.php:

<?php
// 获取毫秒级时间戳
function getMillisecond() {
list($t1, $t2) = explode(' ', microtime());
return (float)sprintf('%.0f', (floatval($t1)+floatval($t2))*1000);
} ?>

在控制器中直接调用即可:

<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
public index() {
$msectime = getMillisecond(); // 不要写成$this->getMillisecond();
echo json_encode(array(
'msectime' => $msectime
));
}
}

2. 自定义公共函数文件

在配置文件./Application/Common/Conf/config.php中加入配置:

'LOAD_EXT_FILE' => 'ifunction',

此时就可以自动加载ifunction.php 文件了。

如果有多个需要自动加载的文件,在配置项的值中以","进行分隔。

最新文章

  1. NYOJ 105
  2. 设计模式学习——观察者模式(Observer Pattern)
  3. React Native组件之Switch和Picker和Slide
  4. Linux Kernel Version Numbering
  5. string引用类型解惑
  6. 不相交集python实现
  7. 设计模式 ( 十七 ):Observer 观察者模式 -- 行为型
  8. Python之路:爬虫之urllib库的基本使用和高级使用
  9. Java_HelloWorld
  10. Fiddler使用总结(一)
  11. 不定期更新的CSS样式设置
  12. Dynamics CRM 2015Online Update1 new feature之 插件跟踪日志
  13. 第8章 CentOS包管理详解
  14. 在a标签内添加hover样式的方法:
  15. Linux命令:mapfile
  16. C#检测本机是否联网
  17. P3110 [USACO14DEC]驮运Piggy Back
  18. L267 How to save money
  19. php编译GD库 JPEG Support
  20. Jmeter(三)Test-Plan、Thread-Group

热门文章

  1. 每日质量NPM包事件绑定_bindme(详解React的this)
  2. 性能跃升50%!解密自主研发的金融级分布式关系数据库OceanBase 2.0
  3. MySQL 并发测试中,线程数和数据库连接池的实验
  4. Digits of Factorial LightOJ - 1045
  5. Utunbu常见问题
  6. 前端调用接口报错看不到报错响应时 console.dir
  7. git tag 用法 功能作用
  8. vue 父组件调用子组件方法
  9. C语言中的多线程编程
  10. Qt5获取本机网络信息