🔥码云GVP开源项目 12k star Uniapp+ElementUI 功能强大 支持多语言、二开方便! 广告
```php class core { private $uri; private $controller = 'Index'; private $action = 'index'; public function __construct() { $this->uri = $_SERVER['PHP_SELF']; $urlField = explode('/', $this->uri); $this->controller = (isset($urlField[2])?$urlField[2]:'Index'); $this->action = (isset($urlField[3])?$urlField[3]:'index'); $this->params = $_GET; } public function getController() { return ucfirst($this->controller); } public function getAction() { return ucfirst($this->action); } } $core = new core(); try { $controllerName = $core->getController(); $controllerPath = sprintf('./app/controller/%s.php', $controllerName); if (!file_exists($controllerPath)) throw new Exception('找不到控制器', 1); require_once $controllerPath; if (!class_exists($core->getController())) throw new Exception('找不到控制器', 1); $controller = new $controllerName; if (!method_exists($controller, $core->getAction())) throw new Exception('方法不存在', 1); echo call_user_func_array(array($controller, $core->getAction()), $_GET); } catch (Exception $e) { echo $e->getMessage(); } ```