PHP与Firebase的连接如何工作? [英] How does PHP connection to firebase work?

查看:747
本文介绍了PHP与Firebase的连接如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您有时间阅读 firebase-php 文档,您可以在这里看到使用助手库连接到 firebase 。但不幸的是,我认为连接只能通过phpunit来建立,换句话说,输出只能在终端中看到。因为当你在浏览器中运行php页面时,它会返回致命错误 。有谁知道如何使用助手库连接到 firebase 数据而不使用 phpunit ?提前感谢您。

解决方案

使用lib非常简单,只需查看测试的源代码即可。 / b>

有两种测试:



现在,为了使用firebase-php,你只需要做和真实功能测试一样的事情。包含lib,使用登录凭据准备连接对象,然后调用所需的方法。 界面描述了您可以在firebaseLib类 -
或只查看 lib源代码本身

这段代码应该让你开始:

  require'/path/to/libs/firebase-php/firebaseLib.php'; 
$ url ='...';
$ token ='...';
$ firebase = new Firebase($ url,$ token);
$ firebase-> get('something / from / somewhere');






如果您通过 composer ,你也可以声明自动加载的类图。

  {
autoload:{
classmap :[vendor / ktamas77 / firebase-php / firebaseLib.php]
}
}

然后,只需使用需要供应商/ autoload.php; 新版Firebase 的Composer自动加载器自动加载类。






如何获得授权令牌




  • 打开您的Firebase控制台
  • 转到项目设置

  • 转到数据库然后复制密钥




If you have the time to read the firebase-php documentation, you can see there how to use the helper library to "connect" to firebase. But unfortunately, I think that the connection could only be established by phpunit, in other words, output can only be seen in the terminal. Since when you run the php pages in your browser, it will return fatal errors. Does anyone know how to use the helper library to connect to the firebase data without using phpunit? Thank you in advance.

解决方案

Using the lib is very easy, when you just look at the source code of the tests.

There are two kinds of tests:

Now, in order to use firebase-php, you would simply do the same things as in the real functionality test. Include the lib, prepare the connection object with login credentials and then call the method you want. The interface describes, which methods you can expect in the firebaseLib class - or just look at the lib source itself.

This piece of code should get you started:

require '/path/to/libs/firebase-php/firebaseLib.php';
$url = '...';
$token = '...';
$firebase = new Firebase($url, $token);
$firebase->get('something/from/somewhere');


If you fetch the library via composer, you might declare an autoloading classmap, too. The author hasn't done this, yet.

{
    "autoload": {
        "classmap": ["vendor/ktamas77/firebase-php/firebaseLib.php"]
    }
}

Then simply require Composer's Autoloader with require "vendor/autoload.php"; and new Firebase to autoload the class.


How to get the auth token

  • open your firebase console
  • go to project settings
  • go to the database
  • then copy the secret key

这篇关于PHP与Firebase的连接如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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