简体   繁体   English

如何在REST请求中将Firebase startAt方法与“值”和“键”一起使用?

[英]How use firebase startAt method with “value” and “key” in REST request?

In web use of firebase, I can use "value" and "key" for the "startAt" method, as demonstrated here: 在Firebase的Web使用中,我可以将“ value”和“ key”用于“ startAt”方法,如此处所示:

https://stackoverflow.com/a/38024909/3466502 https://stackoverflow.com/a/38024909/3466502

And documented here: 并记录在这里:

https://firebase.google.com/docs/reference/js/firebase.database.Reference?hl=pt-br#startAt https://firebase.google.com/docs/reference/js/firebase.database.Reference?hl=pt-br#startAt

But I need this feature in a REST consume and I'm not finding any reference how I should do this. 但是我需要在REST消费中使用此功能,但是我找不到如何执行此操作的任何参考。

Does anyone know how to do this? 有谁知道如何做到这一点?

I am using the PHP packages recommended by Firebase, but in their documentation I have not been able to get information on how I could do this ... :( 我正在使用Firebase推荐的PHP软件包,但是在他们的文档中,我无法获得有关如何执行此操作的信息... :(

I have a data structure like this: 我有这样的数据结构:

"list": {
    "-KsaZNyjd91tEAKjDffA": {"name": "a", "age" => 20},
    "-KsaZNynhTFuDBLpdmKv": {"name": "b", "age" => 21},
    "-KsaZNyoAoYAfHl-f6KF": {"name": "b", "age" => 22},
    "-KsaZiL4HJcoCYksHBEn": {"name": "b", "age" => 23},
    ...
}

I need to return two items per page dynamically. 我需要动态返回每页两个项目。 In JavaScript it was easy doing so: 在JavaScript中,这样做很容易:

var list = firebase.database().ref("list").orderByChild("name").limitToFirst(2);

var page_1 = $firebaseArray(list);
var page_2 = $firebaseArray(list.startAt('b', '-KsaZNyoAoYAfHl-f6KF'));

Using REST I created the following code: 使用REST,我创建了以下代码:

$list = $db->getReference('list')->orderByChild('name')->limitToFirst(2);

$page_1 = $list->getValue();
$page_2 = $list->startAt('b', '-KsaZNyoAoYAfHl-f6KF')->getValue();
//                                      /
// "key" does not work in this method--/

But the "startAt" method of the package does not allow me to determine the "key" as the second parameter and thus the content of the second page is not what is expected. 但是程序包的“ startAt”方法不允许我将“键”确定为第二个参数,因此第二页的内容不是预期的。

Page 1 第1页

{"name": "a", "age" => 20},
{"name": "b", "age" => 21}

Page 2 第2页

{"name": "b", "age" => 21}, // <--- This is the last one on page one
{"name": "b", "age" => 22}  // <--- This should be the first on page 2

I looked at the PHP package method and it did not really implement anything for the "key". 我查看了PHP封装方法,但该方法实际上并未为“键”实现任何东西。 https://firebase-php.readthedocs.io/en/latest/realtime-database.html#startat https://firebase-php.readthedocs.io/en/latest/realtime-database.html#startat

public function startAt($value): Query
    {
        return $this->withAddedFilter(new Filter\StartAt($value));
    }

So I looked at the firebase documentation for REST requests, but I also could not identify which parameter I should specify the "key" of my query. 因此,我查看了REST请求的Firebase文档,但是我也无法确定应该为查询指定“键”的参数。 https://firebase.google.com/docs/database/rest/retrieve-data#consultas-de-intervalo https://firebase.google.com/docs/database/rest/retrieve-data#consultas-de-intervalo

If you look at the code for startAt , it looks like that PHP library doesn't implement the second parameter. 如果您查看startAt代码 ,则该PHP库似乎未实现第二个参数。

Your best bet is to file an issue on the Github repo asking to support the second parameter to startAt() (and endAt() ), or to change the code yourself and file a Pull Request. 最好的选择是在Github存储库上提交问题,要求支持第二个参数startAt() (和endAt() ),或者自己更改代码并提交请求请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM