我对Sonata API有问题。我已经用奏鸣曲管理员捆绑包(页面,新闻等)安装了干净的Symfony 3.4。 我根据文档https://sonata-project.org/bundles/news/3-x/doc/reference/api.html对其进行了配置,但对于页面和新闻API,它仅返回“ {}”。例如:/api/posts.json。
正如我注意到的那样,这些请求在其控制器Sonata \ DatagridBundle \ Pager \ Doctrine对象中正确(包含数据)返回,但是无法序列化。
我的composer.json:
"require": {
"php": ">=5.5.9",
"doctrine/doctrine-bundle": "^1.6",
"doctrine/orm": "^2.5",
"egeloen/ckeditor-bundle": "^6.0",
"friendsofsymfony/ckeditor-bundle": "^1.1",
"friendsofsymfony/rest-bundle": "2.3.1",
"friendsofsymfony/user-bundle": "^2.1",
"incenteev/composer-parameter-handler": "^2.0",
"knplabs/knp-menu-bundle": "2.2.x-dev",
"nelmio/api-doc-bundle": "2.11.0",
"paragonie/random_compat": "v2.0.9",
"pixassociates/sortable-behavior-bundle": "^1.5",
"sensio/distribution-bundle": "^5.0.19",
"sensio/framework-extra-bundle": "^5.0.0",
"sonata-project/admin-bundle": "^3.37",
"sonata-project/cache-bundle": "^2.4",
"sonata-project/datagrid-bundle": "2.3.1",
"sonata-project/doctrine-orm-admin-bundle": "^3.6",
"sonata-project/easy-extends-bundle": "^2.5",
"sonata-project/formatter-bundle": "^3.5",
"sonata-project/news-bundle": "^3.5",
"sonata-project/notification-bundle": "^3.5",
"sonata-project/page-bundle": "3.x-dev",
"sonata-project/seo-bundle": "^2.5",
"stof/doctrine-extensions-bundle": "^1.3",
"symfony-cmf/routing": "^2.1",
"symfony/monolog-bundle": "^3.1.0",
"symfony/polyfill-apcu": "^1.0",
"symfony/swiftmailer-bundle": "^2.6.4",
"symfony/symfony": "3.4.*",
"symfony/templating": "^4.1",
"twig/twig": "^1.0||^2.0"
},
和配置:
fos_rest:
service:
serializer: "fos_rest.serializer.jms"
param_fetcher_listener: true
body_listener: true
format_listener: true
view:
view_response_listener: force
body_converter:
enabled: true
validate: true
exception:
enabled: true
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'
jms_serializer:
metadata:
directories:
sonata_datagrid:
namespace_prefix: "Sonata\\DatagridBundle"
path: "@SonataDatagridBundle/Resources/config/serializer"
日志中没有任何错误。 怎么了?也许有人遇到类似的问题?