PHP code example of fherryfherry / super-framework-engine

1. Go to this page and download the library: Download fherryfherry/super-framework-engine 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/ */

    

fherryfherry / super-framework-engine example snippets


return [
    'driver' => 'mysql', // mysql, pgsql, sqlite, sqlsrv
    'host' => '127.0.0.1',
    'database' => 'super_db',
    'username' => 'root',
    'password' => '',
];

use SuperFrameworkEngine\App\UtilORM\ORM;

// Ambil data berdasarkan ID
$user = db('users')->find(1);

// Ambil semua data
$users = db('users')->all();

$users = db('users')
    ->select('name', 'email')
    ->where('status = ?', ['active'])
    ->whereIn('role_id', [1, 2])
    ->orderBy('created_at desc')
    ->limit(10)
    ->get();

// Mengasumsikan ada kolom user_id di tabel posts
$posts = db('posts')->with('users')->all();

// Cache hasil query selama 60 detik
$products = db('products')->remember(60)->all();

use SuperFrameworkEngine\App\UtilORM\ORM;

ORM::beginTransaction();
try {
    db('orders')->insert([...]);
    db('inventory')->update([...]);
    ORM::commit();
} catch (\Exception $e) {
    ORM::rollback();
}

$results = db()->raw("SELECT * FROM users WHERE age > ?", [25])->fetchAll();

namespace App\Models;

use SuperFrameworkEngine\App\UtilModel\Model;

class User extends Model
{
    protected ?string $table = 'users';
    public $id;
    public $name;
    public $email;
}

// Simpan data baru
$user = new User();
$user->name = "Ferry";
$user->save();

// Update data
$user = User::findById(1);
$user->name = "Updated Name";
$user->save();

// Hapus data
User::delete(1);

// Pagination
$data = User::paginate(15); // Mengembalikan array ['data' => [...], 'total' => 100, 'links' => '...']

use SuperFrameworkEngine\Foundation\Container;

$container = Container::getInstance();

// Binding
$container->singleton(MyService::class, fn() => new MyService());

// Resolving
$service = $container->make(MyService::class);