1. Go to this page and download the library: Download mochrira/selvi-firebase library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
mochrira / selvi-firebase example snippets
$ php index.php migrate main up
namespace App;
use Selvi\Controller as SelviController;
use Selvi\Firebase\Pengguna;
class Controller extends SelviController{
function validateToken() {
Pengguna::validateToken();
}
function validatePengguna() {
Pengguna::validatePengguna();
}
}
namespace App\Controllers;
use App\Controller; /** import your custom controller */
use Selvi\Exception;
use App\Models\Kontak;
class KontakController extends Controller { /** extends that*/
function __construct() {
$this->validateToken(); /** To validate token **/
$this->validatePengguna(); /** To validate pengguna **/
$this->load(Kontak::class, 'Kontak');
}
function rowException($idKontak) {
$data = $this->Kontak->row($idKontak);
if(!$data) {
Throw new Exception('Kontak not found', 'kontak/not-found', 404);
}
return $data;
}
function result() {
$order = [];
$sort = $this->input->get('sort');
if($sort !== null) {
$order = \buildOrder($sort);
}
$orWhere = [];
$search = $this->input->get('search');
if($search !== null) {
$orWhere = \buildSearch(['nmKontak'], $search);
}
$where = [];
return jsonResponse($this->Kontak->result($where, $orWhere, $order));
}
function row() {
$idKontak = $this->uri->segment(2);
$data = $this->rowException($idKontak);
return jsonResponse($data);
}
function insert() {
$data = json_decode($this->input->raw(), true);
$idKontak = $this->Kontak->insert($data);
if($idKontak === false) {
Throw new Exception('Failed to insert', 'kontak/insert-failed');
}
return jsonResponse(['idKontak' => $idKontak], 201);
}
function update() {
$idKontak = $this->uri->segment(2);
$this->rowException($idKontak);
$data = json_decode($this->input->raw(), true);
if(!$this->Kontak->update($idKontak, $data)) {
Throw new Exception('Failed to insert', 'kontak/insert-failed');
}
return response('', 204);
}
function delete() {
$idKontak = $this->uri->segment(2);
$this->rowException($idKontak);
if(!$this->Kontak->delete($idKontak)) {
Throw new Exception('Failed to insert', 'kontak/insert-failed');
}
return response('', 204);
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.