一、示例代码 runtime.php 主要 3个部分, 1、定义系统目录和项目目录 // 路径设置 可在入口文件中重新定义 所有路径常量都必须以/ 结尾defined(core_path) or define(core_path, think_path.lib/); // 系统核心类库目录defined(extend_path) or define(exten
一、示例代码
runtime.php 主要 3个部分,1、定义系统目录和项目目录
// 路径设置 可在入口文件中重新定义 所有路径常量都必须以/ 结尾defined('core_path') or define('core_path', think_path.'lib/'); // 系统核心类库目录defined('extend_path') or define('extend_path', think_path.'extend/'); // 系统扩展目录defined('mode_path') or define('mode_path', extend_path.'mode/'); // 模式扩展目录//省略defined('temp_path') or define('temp_path', runtime_path.'temp/'); // 项目缓存目录defined('data_path') or define('data_path', runtime_path.'data/'); // 项目数据目录defined('cache_path') or define('cache_path', runtime_path.'cache/'); // 项目模板缓存目录
2、载入核心类和基础函数库(common.php)
// 加载系统基础函数库 require think_path.'common/common.php'; // 读取核心文件列表 $list = array( core_path.'core/think.class.php', core_path.'core/thinkexception.class.php', // 异常处理类 core_path.'core/behavior.class.php', ); // 加载模式文件列表 foreach ($list as $key=>$file){ if(is_file($file)) require_cache($file); }
3、创建项目目录
if(!is_dir(lib_path)) { // 创建项目目录结构 build_app_dir(); } /*runtime目录不存在则重新创建runtime目录*/ elseif(!is_dir(cache_path)){ // 检查缓存目录 check_runtime(); }elseif(app_debug){ // 调试模式切换删除编译缓存 if(is_file(runtime_file)) unlink(runtime_file); }
最后就是调用 think.class.php 中的
think::start();
二、值得说的编程小细节:
// 为了方便导入第三方类库 设置vendor目录到include_pathset_include_path(get_include_path() . path_separator . vendor_path);
举例: some.class.php 在 /a/b/c/include 目录下那么在 引入类文件 include '/a/b/c/include/some.class.php';
如果定义了 set_include_path('/a/b/c/include');
只需 include 'some.class.php'; 即可