mirko / t3customroutes
用于注册自定义API端点的TYPO3扩展
0.0.2
2023-02-02 15:32 UTC
Requires
- php: >=8.0.0
- doctrine/annotations: ^1.0
- goldspecdigital/oooas: ^2.4
- phpdocumentor/reflection-docblock: ^5.1
- symfony/cache: ^4.4 || ^5.0 || 6.*
- symfony/expression-language: ^4.1 || ^5.0 || 6.*
- symfony/http-foundation: ^4.2.9 || ^5.0 || 6.*
- symfony/mime: ^4.4 || ^5.0 || 6.*
- symfony/property-info: ^4.4 || ^5.0 || 6.*
- symfony/psr-http-message-bridge: ^2.1
- symfony/routing: ^4.1 || ^5.0 || 6.*
- typo3/cms-core: ^11.5 || 12.*
- typo3/cms-scheduler: ^11.5 || 12.*
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.1
- roave/security-advisories: dev-latest
This package is auto-updated.
Last update: 2024-09-30 01:50:34 UTC
README
-
作者:Mirko团队
-
网站:mirko.in.ua
"自定义路由"扩展(EXT:t3customroutes
)提供了声明自己的API端点和自定义URL的可能性
安装
composer require mirko/t3customroutes
配置
在您的网站config.yaml
文件的底部添加以下行来导入路由增强器。
imports: - { resource: "EXT:t3customroutes/Configuration/Routing/config.yaml" }
如果您不想使用导入,也可以直接在您的网站配置中手动添加新的T3apiResourceEnhancer类型的路由增强器。
routeEnhancers: CustomRoutes: type: RoutesResourceEnhancer
创建自定义API端点
下一步是在EXT:{extkey}/Configuration/routes.yaml
中注册自定义路由
在YAML中创建路由
# config/routes.yaml blog_list: path: /blog # the controller value has the format 'controller_class::method_name' controller: App\Controller\BlogController::list
匹配HTTP方法
默认情况下,路由匹配任何HTTP动词(GET
、POST
、PUT
等)。使用methods选项来限制每个路由应响应的动词
# config/routes.yaml api_post_show: path: /api/posts/{id} controller: App\Controller\BlogApiController::show methods: GET api_post_edit: path: /api/posts/{id} controller: App\Controller\BlogApiController::edit methods: PUT
方法参数
class BlogController { public function list(int $page) { return 'basic api route'; } }
# config/routes.yaml blog_list: path: /blog/{page} controller: App\Controller\BlogController::list defaults: page: 1 blog_show: # ...
您可能还需要在您的扩展中配置依赖注入
贡献
您可以通过向此存储库的master分支提交pull request
来做出贡献。