Firebase与PHP中的Codeigniter连接 [英] Firebase connection with codeigniter in php
问题描述
我想将Firebase数据库与php中的codeigniter项目连接。
I want to connect firebase database with my codeigniter project in php.
我找不到确切的解决方案和库。
I not able to find the exact solution and library..
请推荐正确的库,并按正确的步骤进行连接。
Please recommend the correct library with correct steps that I should follow to connect.
预先感谢。
推荐答案
您可以使用此库 https: //github.com/eelkevdbos/firebase-php
- 安装 kreait / firebase-php 包。
- Install kreait/firebase-php package with Composer.
composer require kreait/firebase-php ^4.18
- 编辑文件
application / config / autoload.php
替换此行。
- Edit file
application/config/autoload.php
replace this following line.
...
$autoload['libraries'] = array('firebase');
...
$autoload['config'] = array('firebase');
...
-
转到 Firebase控制台导航至项目设置->在Firebase Admin SDK选项卡中,单击服务帐户,然后单击生成新私钥。按钮,然后点击生成密钥下载.json文件并保存为项目中的
application / config
文件夹。
Goto Firebase Console navigate to Project settings -> Service accounts in the Firebase Admin SDK tab, click to the "Generate new private key" button then click "Generate key" to download .json file and save as to
application/config
folder in the project.
将第3步中的.json文件名复制到 $ config ['filebase_app_key]中的
数组。 application / config / firebase.php
文件中
Copy your .json file name from step 3. replace it to application/config/firebase.php
file in the $config['filebase_app_key]
array like this.
$config['firebase_app_key'] = __DIR__ . '/../config/your-app-firebase-adminsdk-xxxxx-xxxxxxxxxx.json';
- 现在。您可以像这样在Controller文件中使用firebase库。
$this->load->library('firebase');
$firebase = $this->firebase->init();
$db = $firebase->getDatabase();
您可以在 https://firebase-php.readthedocs.io/en/stable/overview.html#usage-example 。
和
https://www.cloudways.com/blog / php-firebase-integration
这篇关于Firebase与PHP中的Codeigniter连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!