She*_*ngh 5 php codeigniter firebase firebase-realtime-database
我想在 php 中将 firebase 数据库与我的 codeigniter 项目连接起来。
我无法找到确切的解决方案和库..
请推荐正确的库,我应该遵循正确的步骤进行连接。
提前致谢。
小智 5
您可以使用这个库https://github.com/eelkevdbos/firebase-php
composer require kreait/firebase-php ^4.18
Run Code Online (Sandbox Code Playgroud)
application/config/autoload.php替换以下行。...
$autoload['libraries'] = array('firebase');
...
$autoload['config'] = array('firebase');
...
Run Code Online (Sandbox Code Playgroud)
转到Firebase 控制台,导航到 Firebase Admin SDK 选项卡中的“项目设置”->“服务帐户”,单击“生成新私钥”按钮,然后单击“生成密钥”以下载 .json 文件并将其保存到application/config项目中的文件夹中。
复制步骤 3 中的 .json 文件名。将其替换为数组application/config/firebase.php中的文件,$config['filebase_app_key]如下所示。
$config['firebase_app_key'] = __DIR__ . '/../config/your-app-firebase-adminsdk-xxxxx-xxxxxxxxxx.json';
Run Code Online (Sandbox Code Playgroud)
$this->load->library('firebase');
$firebase = $this->firebase->init();
$db = $firebase->getDatabase();
Run Code Online (Sandbox Code Playgroud)
您可以在https://firebase-php.readthedocs.io/en/stable/overview.html#usage-example找到更多使用示例。和 https://www.cloudways.com/blog/php-firebase-integration
小智 1
您可以通过使用https://github.com/eelkevdbos/firebase-php在您的项目中使用 FireBase
use Firebase\Firebase;
$fb = Firebase::initialize(YOUR_FIREBASE_URL, YOUR_FIREBASE_SECRET);
//or set your own implementation of the ClientInterface as second parameter of the regular constructor
$fb = new Firebase([ 'base_url' => YOUR_FIREBASE_BASE_URL, 'token' => YOUR_FIREBASE_SECRET ], new GuzzleHttp\Client());
//retrieve a node
$nodeGetContent = $fb->get('/node/path');
//set the content of a node
$nodeSetContent = $fb->set('/node/path', array('data' => 'toset'));
//update the content of a node
$nodeUpdateContent = $fb->update('/node/path', array('data' => 'toupdate'));
//delete a node
$nodeDeleteContent = $fb->delete('/node/path');
//push a new item to a node
$nodePushContent = $fb->push('/node/path', array('name' => 'item on list'));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19890 次 |
| 最近记录: |