api - 在 api 平台上调用带有 json 数据的控制器
问题描述
我已经使用 make:entity 构建了我的应用程序,
在我创建一个链接所有表以获得我想要的东西的查询之后(所有表的一点)
我的查询正在运行,但现在我想使用 API 平台来处理路由。
但我找不到用 API 平台表示法调用我的控制器的方法。
关于 Caractéristiques 实体的注释。
#[ApiResource(collectionOperations: ['requete' => [
'method' => 'get',
'path' => '/requete',
'controller' => ApiRequeteController::class,
'openapi_context' => [
'summary' => 'get requete',
'requestBody' => [
'content' => [
'application/json' => [
'schema' => [
'type' => 'object',
'properties' =>
[
'montant' => ['type' => 'int'],
'loc' => ['type' => 'string'],
'stat' => ['type' => 'string'],
'type' => ['type' => 'string'],
'sect' => ['type' => 'string'],
],
],
'example' => [
'montant' => 1000000,
'loc' => "test",
'stat' => "test",
'type' => "test",
'sect' => "test",
],
],
],
],
],
],
])]
我找到了这种方式,但不起作用。
给我吗:
语法错误,意外 '=>' (T_DOUBLE_ARROW)
上
'方法' => '得到',
有什么办法可以做到这一点?
解决方案
使用 POST 和另一种写作
* collectionOperations= {"requete" = {
* "method" = "POST",
* "path" = "/requete",
* "controller" = App\Controller\ApiRequeteController::class,
* "openapi_context" = {
* "summary" = "get requete",
* "requestBody" = {
* "content" = {
* "application/json" = {
* "schema" = {
* "type" = "object",
* "properties" =
* {
* "montant" = {"type" = "int"},
* "loc" = {"type" = "string"},
* "stat" = {"type" = "string"},
* "type" = {"type" = "string"},
* "sect" = {"type" = "string"},
* },
* },
* "example" = {
* "montant" = 1000000,
* "loc" = "test",
* "stat" = "test",
* "type" = "test",
* "sect" = "test",
* },
* },
* },
* },
* }
* }
* }
* )
*/
推荐阅读
- templates - openshift编写模板根据条件创建路线
- jquery - 我如何覆盖 jquery show() 事件?
- php - 数据库备份在使用 pdo 的 codeignator 中不起作用
- mvvm - 使用 Flutter 作用域模型时从模型深处通知侦听器
- ruby-on-rails - 如何在 RSpec 中另一个工厂内定义的工厂中定义两个新属性?
- javascript - 如何更改线路共享插件的图像图标
- php - PDO ODBC MYSQL:我尝试连接,但它给了我一个致命错误
- r - 如何`grep()`只有数字和浮点数以及带有数字/浮点数的符号而不是带有数字的字符
- javascript - 如何在axios中得到正确的答案形式
- reflection - 如何使用 callBy() 调用 Kotlin 配套工厂方法?