* D函數用於實例化Model 格式 項目://分組/模塊
* @param string $name Model資源地址
* @param string $layer 業務層名稱
* @return Modelphp
測試項目地址:http://www.yixingmuban.com/app
function D($name='',$layer='') { if(empty($name)) return new Model; static $_model = array(); $layer = $layer?$layer:C('DEFAULT_M_LAYER'); if(strpos($name,'://')) {// 指定項目 list($app) = explode('://',$name); $name = str_replace('://','/'.$layer.'/',$name); }else{ $app = C('DEFAULT_APP'); $name = $app.'/'.$layer.'/'.$name; } if(isset($_model[$name])) return $_model[$name]; $path = explode('/',$name); if($list = C('EXTEND_GROUP_LIST') && isset($list[$app])){ // 擴展分組 $baseUrl = $list[$app]; import($path[2].'/'.$path[1].'/'.$path[3].$layer,$baseUrl); }elseif(count($path)>3 && 1 == C('APP_GROUP_MODE')) { // 獨立分組 $baseUrl = $path[0]== '@' ? dirname(BASE_LIB_PATH) : APP_PATH.'../'.$path[0].'/'.C('APP_GROUP_PATH').'/'; import($path[2].'/'.$path[1].'/'.$path[3].$layer,$baseUrl); }else{ import($name.$layer); } $class = basename($name.$layer); if(class_exists($class)) { $model = new $class(basename($name)); }else { $model = new Model(basename($name)); } $_model[$name] = $model; return $model; }