資源控制器可以讓你輕松的創建RESTFul API,可以通過代碼生成功能生成需要的資源控制器,例如:
// 生成appstore模塊的appstore資源控制器
默認在/catch/appstore/route.php文件中為資源控制器注冊了一個資源路由:
~~~
$router->resource('appstore', '\catchAdmin\appstore\controller\Appstore');
~~~
設置后會自動注冊5個路由規則,如下:
| 接口地址 | 請求類型 | 生成路由規則 | 對應操作方法 |
| --- | --- | --- | --- |
| https://serverName/appstore | GET | appstore | index |
| https://serverName/appstore | POST | appstore | save |
| https://serverName/appstore/1 | GET | appstore /:id | read |
| https://serverName/appstore/1 | PUT | appstore /:id | update |
| https://serverName/appstore/1 | DELETE | appstore /:id | delete |
就可以通過https://serverName/appstore 資源路由接口 實現對資源的訪問和操作。
可以通過在model/search目錄下添加查詢trait,并在model中使用trait,以支持index操作方法進行定制化的查詢操作。可以參考 catch/permissions/model/search/UserSearch.php trait和 catch/permissions/model/Users的實現。