DataMapper all_to_json()方法返回斜杠 [英] DataMapper all_to_json() method returning slashes

查看:140
本文介绍了DataMapper all_to_json()方法返回斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚发现DataMapper for CI内置在 to_json all_to_json 方法,这节省了我很多时间。

I just found DataMapper for CI's built in to_json and all_to_json methods, which saved me a ton of time.

如何返回与结果的关系?

How can I return relations with the result?

目前我的代码如下:

$homes = new Home();

$homes->include_related('address')->get();
$homes->include_related('album')->get();

$homes->get();

$homes->set_json_content_type();
echo $homes->to_json();

但是我只是回家了,而不是嵌套的信息。

However I'm only getting back the home itself, rather than the nested information.

编辑:

我发现你可以简单地将这些字段添加到数组参数,但是,如果我使用 all_to_json($ fields); 它完全返回第一行,但第二个嵌套返回为NULL。仍然认为这是我的错,但我不知道有没有人看过这个。

I've found that you can simply add those fields to the array parameter, however, if I use all_to_json($fields); it returns the first row perfectly, but the second nested comes back as NULL. Still think it's my fault, but I didn't know if anyone's seen this before.

这是我目前的输出。

{
    "id": 1,
    "latitude": "0",
    "longitude": "0",
    "price": "173000",
    "sqft": "2100",
    "room_count": "3",
    "bath_count": "2",
    "created": "1333209034",
    "updated": "1333209034",
    "status": "active",
    "address": [
        1
    ],
    "album": []
}

如果我查看原始输出,我看到完整的地址。在我的JSON中,我看到一个数字1.如何显示这个数据而不是数字?

In my data, if I view the raw output, I see the full address. In my JSON I see a number 1. How can I display this data rather than the number?

推荐答案

发布版本不递归,以避免生成巨大的JSON输出(取决于加载的对象,这可以很快耗尽内存)。

The 1.8.2. release version doesn't recurse, to avoid generating gigantic JSON ouput (depending on the loaded object this can run out of memory very quickly).

有一些更新可用作为即将到来的1.8.3版本的一部分,bitbucket上的JSON扩展。

There are some updates available to the JSON extension on bitbucket as part of the upcoming 1.8.3 release.

新功能的一部分是你可以传递一个相关对象的列表,深层关系符号(如儿童,儿童/孙子,儿童/其他,儿童/其他/相关,...)。

On of the new features is that you can pass it a list of related objects it has to recurse into, in deep relationship notation (like "child", "child/grandchild", "child/other", "child/other/related", ...).

这篇关于DataMapper all_to_json()方法返回斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆