grptx/yii2-firebase

连接到 Firebase 数据库的 Yii2 组件

安装次数: 19,645

依赖者: 0

建议者: 0

安全性: 0

星标: 14

关注者: 3

分支: 13

开放问题: 1

类型:yii2-extension

v0.4 2018-06-17 19:45 UTC

This package is auto-updated.

Last update: 2024-09-18 23:44:51 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License

此 Yii2 组件包装了 kreait/firebase-php,允许轻松连接到 Firebase 实时数据库

安装

推荐通过 Composer 安装

php composer.phar require grptx/yii2-firebase:~0.3.1

或者,你可以在你的 composer.json 文件的 require 部分添加

"grptx/yii2-firebase": "~0.3.1"

然后执行 php composer.phar update

配置

...
'components' => [
    'firebase' => [
        'class'=>'grptx\Firebase\Firebase',
        'credential_file'=>'service_account.json', // (see https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app)
        'database_uri'=>'https://my-project.firebaseio.com', // (optional)
    ]
...
]

可选

为了使用 IDE(例如 Phpstorm)的自动完成功能,你可以选择在 web/index.php 中替换 Yii.php 文件的包含和应用实例

替换

require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php');
//and 
(new yii\web\Application($config))->run();

require (__DIR__.'/../../vendor/grptx/yii2-firebase/src/yii2/Yii.php');
//and
(new \grptx\Firebase\web\Application($config))->run();

现在,当你需要时,你可以使用 grptx\Firebase\yii2\Yii 而不是 Yii 来使用 IDE 的自动完成功能

使用方法

检索一个 数据库引用 和一个

$database = Yii::$app->firebase->getDatabase();
$reference = $database->getReference('path/to/child/location');
$value = $reference->getValue();

或者只是 引用 和一个

$reference = Yii::$app->firebase->getReference('path/to/child/location');
$value = $reference->getValue();

有关其他方法的详细信息,请参阅 firebase-php.readthedocs.io.