【问题标题】:Silverstripe Restfulapi configurationSilverstripe Restfulapi 配置
【发布时间】:2019-10-18 05:34:13
【问题描述】:

我尝试使用 silverstripe 4 的 Restfulapi 插件,我的配置是:

integre\About:
  api_access: true
integre\Home:
  api_access: true
Image:
  api_access: true
File:
  api_access: true
integre\Theatre:
  api_access: true
# RestfulAPI config
Colymba\RESTfulAPI\RESTfulAPI:
  authentication_policy: false
  access_control_policy: 'ACL_CHECK_CONFIG_AND_MODEL'
  cors:
    Enabled: true
    Allow-Origin: '*'
    Allow-Headers: '*'
    Allow-Methods: 'OPTIONS, POST, GET, PUT, DELETE'
    Max-Age: 86400

但是当我尝试http://localhost/integre/api/Theatre/1 时,我收到了 { “代码”:400, “消息”:“模型不存在。收到‘剧院’。” }

如何解决这个问题?

【问题讨论】:

    标签: silverstripe silverstripe-4


    【解决方案1】:

    您的问题是您使用的是命名空间类,但未正确配置它以在 API 中使用,因此无法正确解析。看DefaultQueryHandler,需要define a class name map for this

    Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler:
      models:
        Theatre: integre\Theatre
    

    这告诉查询处理程序在请求Theatre 模型时加载integre\Theatre。请注意,配置中的 Image 和 File 引用也缺少它们的命名空间。

    【讨论】:

    • 我尝试?__limit[]=count&__limit[]=offset进行分页,但最后没有显示分页Json,如何接收分页Json?
    • 我不知道,但这听起来像是一个不同的问题 :-)
    猜你喜欢
    • 2021-07-07
    • 1970-01-01
    • 2019-10-28
    • 2021-10-26
    • 2019-02-21
    • 2018-08-09
    • 1970-01-01
    • 1970-01-01
    • 2015-01-06
    相关资源
    最近更新 更多