elfadl / yii2-firebase-helper
Yii2 Component to connect to Firebase Database
Installs: 5
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- kreait/firebase-php: ^5.0
- yiisoft/yii2: ^2
Requires (Dev)
This package is auto-updated.
Last update: 2024-11-09 11:38:03 UTC
README
This Yii2 component wraps kreait/firebase-php and allow to easy connect to the Firebase realtime database
Installation
Preferred way to install is through Composer:
php composer.phar require elfadl/yii2-firebase-helper
Configuration
... 'components' => [ 'firebase' => [ 'class'=>'elfadl\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) ] ... ]
Optional
to use the autocomplete function of IDE (i.e. Phpstorm) you can optionally replace in the web/index.php the inclusion of Yii.php file and the Application instance:
replace:
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); //and (new yii\web\Application($config))->run();
with:
require (__DIR__.'/../../vendor/grptx/yii2-firebase/src/yii2/Yii.php'); //and (new \elfadl\Firebase\web\Application($config))->run();
now when you need you can use elfadl\Firebase\yii2\Yii instead of Yii to use autocomplete of your IDE
Usage
Retrive a database ,reference and a value
$database = Yii::$app->firebase->getDatabase(); $reference = $database->getReference('path/to/child/location'); $value = $reference->getValue();
or just the reference and a value
$reference = Yii::$app->firebase->getReference('path/to/child/location'); $value = $reference->getValue();
for other method see firebase-php.readthedocs.io.