Browse Source

add multiple user support

master
filesite 7 months ago
parent
commit
e8c81218d0
  1. 27
      lib/FSC.php

27
lib/FSC.php

@ -48,7 +48,24 @@ Class FSC {
$arr = parse_url($url); $arr = parse_url($url);
$path = !empty($arr['path']) ? $arr['path'] : '/'; $path = !empty($arr['path']) ? $arr['path'] : '/';
$controller = $action = $user_id = '';
if (!empty($config['multipleUserUriParse'])) { //如果开启了多用户解析支持
$pathArr = explode('/', $path);
if (count($pathArr) >= 2 && is_numeric($pathArr[1])) {
$user_id = $pathArr[1];
if (!empty($pathArr[2])) {
$controller = $pathArr[2];
}
if (!empty($pathArr[3])) {
$action = $pathArr[3];
}
}else {
@list(, $controller, $action) = $pathArr;
}
}else {
@list(, $controller, $action) = explode('/', $path); @list(, $controller, $action) = explode('/', $path);
}
if (empty($controller)) { if (empty($controller)) {
$controller = !empty($config['defaultController']) ? $config['defaultController'] : 'site'; $controller = !empty($config['defaultController']) ? $config['defaultController'] : 'site';
}else if(preg_match('/\w+\.\w+/i', $controller)) { //not controller but some file not exist }else if(preg_match('/\w+\.\w+/i', $controller)) { //not controller but some file not exist
@ -63,7 +80,7 @@ Class FSC {
$action = preg_replace('/\W/', '', $action); $action = preg_replace('/\W/', '', $action);
} }
return compact('controller', 'action'); return compact('controller', 'action', 'user_id');
} }
//add themes support //add themes support
@ -73,10 +90,16 @@ Class FSC {
$arr = self::getControllerAndAction($requestUrl, $config); $arr = self::getControllerAndAction($requestUrl, $config);
$controller = $arr['controller']; $controller = $arr['controller'];
$action = $arr['action']; $action = $arr['action'];
$user_id = $arr['user_id'];
$start_time = self::$start_time; $start_time = self::$start_time;
//如果多用户解析支持开启
if (!empty($config['multipleUserUriParse']) && !empty($user_id)) {
$config['content_directory'] = "{$config['content_directory']}{$user_id}/";
}
//set parameters //set parameters
self::$app = compact('config', 'controller', 'action', 'requestUrl', 'start_time'); self::$app = compact('config', 'controller', 'action', 'user_id', 'requestUrl', 'start_time');
//call class and function //call class and function
$className = ucfirst($controller) . 'Controller'; $className = ucfirst($controller) . 'Controller';

Loading…
Cancel
Save