RESTful路由

  1. Router::get('/', \App\Controllers\IndexController::class . '@index');
  2. Router::post('/', \App\Controllers\IndexController::class . '@' . 'post');
  3. Router::put('/', \App\Controllers\IndexController::class . '@' . 'put');
  4. Router::delete('/', \App\Controllers\IndexController::class . '@' . 'delete');
  5. Router::patch('/', \App\Controllers\IndexController::class . '@' . 'patch');
  6. Router::head('/', \App\Controllers\IndexController::class . '@' . 'head');
  7. Router::options('/', \App\Controllers\IndexController::class . '@' . 'options');

或者直接用

  1. Router::controller('/', \App\Controllers\IndexController::class);

要求\App\Controllers\IndexController中包含 getActionpostActionputActiondeleteActionpatchActionheadActionoptionsAction 方法。

除上面方法外你可通过set自定义任意方法

Router::set(请求方法,请求路径,绑定执行的方法);

  1. Router::set('xxx','/a','TestController@abc');

列入增加ws方法,设置为websocket路由。

  1. Router::set('ws','/a','TestController@abc');