【问题标题】:Fluid Query Result object to JSON将流体查询结果对象转换为 JSON
【发布时间】:2018-06-19 08:33:57
【问题描述】:

我的视图中有一个结果对象,并希望将其放入 JSON 格式。

对象看起来像

TYPO3\CMS\Extbase\Persistence\Generic\QueryResultprototypeobject (32 items)
0 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=853, 
pid=90)
1 => KN\Operations\Domain\Model\Operationprototypepersistent entity (uid=852, 
pid=90)
....

我尝试使用格式

{myObject-> f:format.json()}

但这不起作用。结果是

{}

我想将这些信息提供给我的 JS。对我来说,不可能更改控制器,因为我不想更改现有的扩展。

【问题讨论】:

标签: typo3 fluid


【解决方案1】:

format.json 视图助手需要一个数组作为值。要获得正确的结果,您需要将结果转换为数组。 如果您将存储库中执行函数的第一个参数设置为 true,您将获得一个数组而不是 Queryresult 对象。

return $query->execute(true);

您可以在 viewhelper 的文档页面上找到更多信息:https://docs.typo3.org/typo3cms/ExtbaseGuide/Fluid/ViewHelper/Format/Json.html

编码愉快!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-12-29
    • 2016-12-23
    • 1970-01-01
    • 1970-01-01
    • 2017-10-03
    • 1970-01-01
    • 2021-12-05
    • 1970-01-01
    相关资源
    最近更新 更多