<?php if(!defined(‘COREINC‘)) exit(‘Request Error!‘); //统一配置文件,优先使用自定义配置,未定义的使用默认配置 defined("CORE_PATH") or define("CORE_PATH", "./core/"); //框架核心路径 defined("APP_PATH") or define("APP_PATH","./app/");//项目路径 defined(‘MODEL_PATH‘) or define("MODEL_PATH",APP_PATH.‘models/‘); defined(‘STATIC_PATH‘) or define(‘STATIC_PATH‘,APP_PATH.‘statics/‘); defined("UP_PATH") or define(‘UP_PATH‘, APP_PATH.‘upload/‘); defined("PLUGIN_PATH") or define("PLUGIN_PATH", APP_PATH.‘plugin/‘); //字符编码 defined("CHARSET") or define(‘CHARSET‘,‘utf-8‘); // 定义当前请求的系统常量 define(‘NOW_TIME‘, $_SERVER[‘REQUEST_TIME‘]); define(‘REQUEST_METHOD‘,$_SERVER[‘REQUEST_METHOD‘]); define(‘IS_GET‘, REQUEST_METHOD ==‘GET‘ ? true : false); define(‘IS_POST‘, REQUEST_METHOD ==‘POST‘ ? true : false); define(‘IS_PUT‘, REQUEST_METHOD ==‘PUT‘ ? true : false); define(‘IS_DELETE‘, REQUEST_METHOD ==‘DELETE‘ ? true : false); define(‘IS_AJAX‘, ((isset($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) == ‘xmlhttprequest‘)) ? true : false); //设置include_path set_include_path(get_include_path() . PATH_SEPARATOR . CORE_PATH."main"); initializer::initialize();//加载将要用到的目录文件 require_once(CORE_PATH."functions/global.fun.php");//公用方法 require_once(APP_PATH.‘config/config.php‘);//自定义配置文件 require_once(CORE_PATH."config/config.php");//默认配置文件 $common_fun_path = APP_PATH.‘common/common.php‘; if(file_exists($common_fun_path)){ require_once($common_fun_path); } //自动加载类 function __autoload($object){ require_once("{$object}.class.php"); } ?>
defined("CORE_PATH") or define("CORE_PATH", "./core/"); //框架核心路径
框架默认核心路径,如果入口文件不配置,就默认该配置
defined("APP_PATH") or define("APP_PATH","./app/");//项目路径
项目默认路径,如果入口文件不配置,就默认该配置
defined(‘MODEL_PATH‘) or define("MODEL_PATH",APP_PATH.‘models/‘); defined(‘STATIC_PATH‘) or define(‘STATIC_PATH‘,APP_PATH.‘statics/‘); defined("UP_PATH") or define(‘UP_PATH‘, APP_PATH.‘upload/‘); defined("PLUGIN_PATH") or define("PLUGIN_PATH", APP_PATH.‘plugin/‘);
分别为 模型路径,静态文件路径,上传路径,差距路径的默认配置,一般可以在config.php文件中配置,如果不配置,就默认该配置
defined("CHARSET") or define(‘CHARSET‘,‘utf-8‘);
配置字符编码,再global.fun.php中有函数str_cut用得到,下面是字符串截取函数str_cut得代码
function str_cut($string, $length, $dot = ‘‘) { $strlen = strlen($string); if($strlen/2 <= $length) return $string; $string = str_replace(array(‘ ‘,‘ ‘,‘ ‘,‘ ‘, ‘&‘, ‘"‘, ‘\‘‘, ‘“‘, ‘”‘, ‘—‘, ‘<‘, ‘>‘, ‘·‘, ‘…‘), array(‘ ‘,‘ ‘,‘ ‘,‘ ‘, ‘&‘, ‘"‘, "‘", ‘“‘, ‘”‘, ‘—‘, ‘<‘, ‘>‘, ‘·‘, ‘…‘), $string); $strcut = ‘‘; $n = $tn = $noc = 0; if(strtolower(CHARSET) == ‘utf-8‘) { while($n < $strlen) { $t = ord($string[$n]); if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) { $tn = 1; ++$n; $noc += 0.5; } elseif(194 <= $t && $t <= 223) { $tn = 2; $n += 2; $noc += 1; } elseif(224 <= $t && $t <= 239) { $tn = 3; $n += 3; $noc += 1; } elseif(240 <= $t && $t <= 247) { $tn = 4; $n += 4; $noc += 1; } elseif(248 <= $t && $t <= 251) { $tn = 5; $n += 5; $noc += 1; } elseif($t == 252 || $t == 253) { $tn = 6; $n += 6; $noc += 1; } else { ++$n; } if($noc >= $length) { if($n < $strlen) ++$noc; break; } } } else { while($n < $strlen) { if(ord($string[$n]) > 127) { $tn = 2; $n += 2; $noc += 1; } else{ $tn = 1; ++$n; $noc += 0.5; } if($noc >= $length) { if($n < $strlen) ++$noc; break; } } } if($noc > $length && !empty($dot)) { $n -= $tn; $strcut = substr($string, 0, $n); $strcut .= $dot; }else{ $strcut = substr($string, 0, $n); } $strcut = str_replace(array(‘&‘, ‘"‘, "‘", ‘“‘, ‘”‘, ‘—‘, ‘<‘, ‘>‘, ‘·‘, ‘…‘), array(‘&‘, ‘"‘, ‘\‘‘, ‘“‘, ‘”‘, ‘—‘, ‘<‘, ‘>‘, ‘·‘, ‘…‘), $strcut); return $strcut; }
下面定义的常量,用于判断请求类型
// 定义当前请求的系统常量 define(‘NOW_TIME‘, $_SERVER[‘REQUEST_TIME‘]); define(‘REQUEST_METHOD‘,$_SERVER[‘REQUEST_METHOD‘]); define(‘IS_GET‘, REQUEST_METHOD ==‘GET‘ ? true : false); define(‘IS_POST‘, REQUEST_METHOD ==‘POST‘ ? true : false); define(‘IS_PUT‘, REQUEST_METHOD ==‘PUT‘ ? true : false); define(‘IS_DELETE‘, REQUEST_METHOD ==‘DELETE‘ ? true : false); define(‘IS_AJAX‘, ((isset($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) && strtolower($_SERVER[‘HTTP_X_REQUESTED_WITH‘]) == ‘xmlhttprequest‘)) ? true : false);
设置include_path
//设置include_path set_include_path(get_include_path() . PATH_SEPARATOR . CORE_PATH."main");
自动加载
//自动加载类 function __autoload($object){ require_once("{$object}.class.php"); }
该函数的工作原理如下:
http://www.cnblogs.com/bourneli/archive/2012/09/08/2676965.html
initializer::initialize();//加载将要用到的目录文件
自动加载类,
<?php if(!defined(‘COREINC‘)) exit(‘Request Error!‘); class initializer{ public static function initialize() { //set_include_path(get_include_path().PATH_SEPARATOR.CORE_PATH."main"); set_include_path(get_include_path().PATH_SEPARATOR.CORE_PATH."helpers"); set_include_path(get_include_path().PATH_SEPARATOR.CORE_PATH."libraries"); set_include_path(get_include_path().PATH_SEPARATOR.CORE_PATH."config"); set_include_path(get_include_path().PATH_SEPARATOR.APP_PATH."controllers"); set_include_path(get_include_path().PATH_SEPARATOR.APP_PATH."models"); set_include_path(get_include_path().PATH_SEPARATOR.APP_PATH."views"); set_include_path(get_include_path().PATH_SEPARATOR.APP_PATH."config"); set_include_path(get_include_path().PATH_SEPARATOR.APP_PATH."plugin"); } }?>
该静态方式调用,设置了一些要用到的include_path
require_once(CORE_PATH."functions/global.fun.php");//公用方法 require_once(APP_PATH.‘config/config.php‘);//自定义配置文件 require_once(CORE_PATH."config/config.php");//默认配置文件 $common_fun_path = APP_PATH.‘common/common.php‘; if(file_exists($common_fun_path)){ require_once($common_fun_path); }
加载公用方法,公用(默认)配置文件,项目配置文件以及项目common.php(如果存在该文件)
附:core框架核心目录一览
项目文件目录一览
原文:http://www.cnblogs.com/doujinya/p/3836204.html