我尝试了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, “ message”:“模型不存在。收到了”剧院“。 }
该如何解决?
答案 0 :(得分:2)
您的问题是您使用的是命名空间类,并且未正确配置要在API中使用的类,因此无法正确解析。查看DefaultQueryHandler
,您需要define a class name map for this:
Colymba\RESTfulAPI\QueryHandlers\DefaultQueryHandler:
models:
Theatre: integre\Theatre
这告诉查询处理程序在要求提供integre\Theatre
模型时加载Theatre
。请注意,配置中的“图像”和“文件”引用也缺少其名称空间。