ThinkPHP3自动加载公共函数文件
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 文件了。
如果有多个需要自动加载的文件,在配置项的值中以","进行分隔。
ThinkPHP3自动加载公共函数文件的更多相关文章
- ThinkPHP 3.2.3 自动加载公共函数文件的方法
方法一.加载默认的公共函数文件 在 ThinkPHP 3.2.3 中,默认的公共函数文件位于公共模块 ./Application/Common 下,访问所有的模块之前都会首先加载公共模块下面的配置文件 ...
- laravel 自动加载 自定义的文件/辅助函数
需求 在 laravel 中自定义了一些 辅助函数,想要laravel框架自动加载这些函数 实现 将自定义的辅助函数放在helpers.php文件中,如下: 在compsoer.json 的 auto ...
- Eclipse下SpringBoot没有自动加载application.properties文件
Eclipse内创建SpringBoot项目,在java/main/resources文件夹下面创建application.properties配置文件,SpringApplication.run后发 ...
- spring boot注解 --@spring-boot-devtools 自动加载修改的文件和类
spriing boot中有一个注解,是自动加载修改后的类或者文件. 使用方法为: spring-boot-devtools=true 需要引入devtools包依赖: <dependency& ...
- laravel自动加载公共文件
1. 创建 functions.php 在 app/Common/(目录自己起名字)下新建一个文件 functions.php,在内部补充如下代码: <?php /** 数据返回 * 返回jso ...
- java web项目启动时自动加载自定义properties文件
首先创建一个类 public class ContextInitListener implements ServletContextListener 使得该类成为一个监听器.用于监听整个容器生命周期的 ...
- 访问项目时,不能自动加载index.php文件
1.修改配置文件D:\lamp\apache\conf\httpd.conf加上DirectoryIndex index.hmtl index.php <IfModule !mpm_netwar ...
- laravel 配置自动加载多路由文件
在 app\Providers\RouteServiceProvider文件下增加方法&注册: 增加之后就可以在routers下建立api文件夹,在里面添加路由了
- 010.CI4框架CodeIgniter, autoload自动加载自己的helper函数类
01.自己定义了一个helper类,里面有个函数用来输出 02.定义一个Controller基本类,我们以后用到的Controllers类都继承自这个类.其中自动加载helper函数如图所示: 03. ...
随机推荐
- getAttribute与getParameter的区别
1.getParameter得到的是字符串,其取值源于jsp页面,从jsp页面中接受一个存在的参数,多用于servlet中,用于判断业务的类型和跳转页面.如: request.getParameter ...
- BMv2 simple_switch 运行时切换P4程序
参考: [P4-dev] swapping p4 program using load_new_config and swap_configs commands BMv2 运行时切换P4程序 相关演示 ...
- sprinf sprintf_s 的用法
函数功能: 将数据格式化输出到字符串 函数原型: int sprintf( char *buffer, const char *format [,argument] ... ) 注意这里的buffer ...
- .Net MVC关于子页面引用js库问题
layout页面中的配置: @RenderSection("scripts", required: false) @RenderSection("Styles" ...
- art-template实战
内容div <div id="sku-cont"> <div class="form-group col-lg-12"> <div ...
- C++.sprintf
ZC:sprintf,sprintf_s 1.经测试 sprintf,是会在字符串的最后 加上'\0'的,∴ 不用担心 字符串的结尾的问题 2. 3. 4. 5.
- [原][qt]解决qt在vs下could not find or load the Qt platform plugin "windows" in ""问题
在VS上开发qt遇到问题: 解决: 在main最开始加入: QTextCodec *xcodec = QTextCodec::codecForLocale(); QString exeDir = xc ...
- java.io.FileNotFoundException异常,一是“拒绝访问”,二是“系统找不到指定路径”
关于java.io.FileNotFoundException异常 因为这个异常抛出俩种情况:一是“拒绝访问”,二是“系统找不到指定路径” 这里只讲明什么时候抛拒绝访问,什么时候抛找不到指定路径. 原 ...
- 关于fstream、ifstream、ofstream读写文本文件、二进制文件详解
fstream.ifstream.ofstream是c++中关于文件操作的三个类 fstream类对文件进行读操作和写操作 打开文件 fstream fs("要打开的文件名",打开 ...
- (转)Qt中图片相对位置的引用
原文作者:locky1218 原文地址:https://blog.csdn.net/locky1218/article/details/9749703/ 一般使用相对位置的时候可能无法显示图片,可 ...