header("Content-type: text/html; charset=utf-8");
session_start();
class Cool{
private static $db_static = null;
function __get($a=''){
if(!self::$db_static){
include("class/db_class.php");
include("inc/oa_config.php");
$dbarr=array("host"=>$MYSQL_SERVER,"user"=>$MYSQL_USER,"pass"=>$MYSQL_PASS,"dbname"=>$MYSQL_DB,"charset"=>"utf8");
self::$db_static = new DB($dbarr);
}
return $this->db=self::$db_static;
}
function load_class($cname,$params=''){
include_once("./class/".$cname.".php");
$this->$cname=new $cname($params);
}
function load_view($tmp,$data_arr=array()){
if(is_array($data_arr))
foreach($data_arr as $k=>$v){
$$k=$v;
}
include_once("./views/".$tmp.".php");
}
}
function load_controller(){
$c = $_GET['c'];
$m = ($_GET['m']) ? $_GET['m'] : 'index';;
// $c =uri(0);
// $m = uri(1);
$ph="./controllers/". $c . '.php';
include_once($ph);
$controller=new $c();
$controller->$m();
}
load_controller();
function json_error($msg,$errcode=1){
echo json_encode(array("errcode"=>$errcode,"errmsg"=>$msg));exit;
}
function json_array($ph){//读取json并转化array
$vstr=file_get_contents($ph);
return json_decode($vstr,true);
}
function uri($p){
$uris=explode("/",explode("&",$_SERVER['QUERY_STRING'])[0]);
return $uris[$p];
}
function msg($msg){
include_once('views/msg.php');exit;
}
主控制器
最新推荐文章于 2022-11-06 20:51:37 发布