abstrait:try{ //獲取類名與方法 $uri = parse_url($_SERVER['PATH_INFO']); $query = $uri['p
try{ //獲取類名與方法 $uri = parse_url($_SERVER['PATH_INFO']); $query = $uri['path']; $pathInfo = array_values(array_filter(explode('/',$query))); $className = ucfirst(isset($pathInfo[0])?$pathInfo[0]:''); $methodName = isset($pathInfo[1])?$pathInfo[1]:''; if(!$className||!$methodName){ throw new \Exception(); } $methodNameArr = explode('_',$methodName); $method = ''; foreach ($methodNameArr as $key=>$value){ if($key!=0){ $method.=ucfirst($value); }else{ $method=$value; } } //獲取查詢參數(shù) $params = $_GET; $fileDir = $className.'.php'; include_once $fileDir; $classObj = new $className(); $data = $classObj->$method($params); exit($data); }catch (\Exception $e){ Header("HTTP/1.0 404 Not Found"); } ?>
Professeur correcteur:天蓬老師Temps de correction:2019-03-28 17:14:42
Résumé du professeur:很用心, 自己改寫了案例代碼,并加上了異常機制, 不錯, 但是異常類沒有參數(shù), 如果有的話, 通常會配全常量用的, 要注意一下