add('', ['controller' => 'Home', 'action' => 'index']); $router->add('{controller}/{action}'); $router->add('{controller}/{action}/{id:.+}'); $router->AddPrefix(\App\Config::ROUTE_PREFIX); try{ //for prefight request if($_SERVER['REQUEST_METHOD'] == 'OPTIONS'){ header('Access-Control-Allow-Origin:*'); header('Access-Control-Allow-Methods:OPTIONS, GET, POST'); // 允许option,get,post请求 header('Access-Control-Allow-Headers:x-requested-with'); // 允许x-requested-with请求头 header('Access-Control-Allow-Headers:content-type,x-ijt'); // 允许x-requested-with请求头 print ""; return; }else{ $router->dispatch($_SERVER['REQUEST_URI']); } }catch (Exception $exception){ echo $exception; }