header("Content-type:text/html;charset=utf-8");//文件编码格式
windows下使用的是“\”作为分隔符,而linux则反其道而行之使用"/"作为分隔符。所以在windows 环境中获取路径常见 C:\windows\system 的形式,而linux 常见 /user/share 的形式。 PHP中使用$_SERVER[‘DOCUMENT_ROOT‘] 和 dirname(__FILE__)可以获取两个路径。 在linux下获取的这两个路径使用的都是Linux文件系统"/"作为分隔符的;而windows中获取的这两个路径则不是都使用windows文件系统"\"作为分隔符的。 $_SERVER[‘DOCUMENT_ROOT‘] 在linux和windows下均返回以"/"作为分隔符的文件路径 dirname(__FILE__)在linux下使用“/”作为路径分隔符,在windows下使用”\“作为分隔符
//获取当前文件的路径得到项目的根目录 并且将‘/’转换为‘\‘ $len = str_replace(‘\\‘, ‘/‘, dirname(dirname(__FILE__))).‘/‘;
define(‘ROOT‘,$len);
//引入函数库 include(ROOT.‘include/lib.base.php‘);
//自动加载 function webcyhLoad($class){ //将转换成小写的截取到的类名与model比较 if(strtolower(substr($class, -5)) == ‘model‘){ //引入Model文件 require(ROOT.‘Model/‘.$class.‘.class.php‘); //引入工具类 }else if(strtolower(substr($class, -4)) == ‘tool‘){ require(ROOT.‘tools/‘.$class.‘.class.php‘); }else{ //引入其他类文件 require(ROOT.‘include/‘.$class.‘.class.php‘); } } //这里先执行MySmarty当中的自动加载 include(ROOT.‘include/MySmarty.class.php‘); //再次执行当前的自动加载 spl_autoload_register(‘webcyhLoad‘);
//全局smarty $smarty = new MySmarty();
session_start(); //预定义 开启调试 define(‘DEBUG‘,true); //判断如果开启调试 if(defined(‘DEBUG‘)&&DEBUG){ error_reporting(E_ALL); }else{ //否则不输出任何错误 error_reporting(0); }
注意注册的自动加载和smarty当中的自动加载的冲突解决方法
将两者的顺序调换
原文:https://www.cnblogs.com/webcyh/p/11312634.html