Sebuah proyek PHP sederhana tanpa framework untuk mendemonstrasikan arsitektur Front Controller + MVC
Menggunakan:
- Vanilla PHP
- SQLite (file-based database)
- 98.css (UI retro Windows 98)
- Belajar konsep dasar MVC tanpa framework
- Memahami cara kerja routing manual
- Mengenal pola hubungan antara Controller → Model → View
project/
│
├── public/
│ └── index.php # Front Controller (entry point)
│
├── src/
│ ├── Controllers/
│ │ └── BookController.php
│ │
│ ├── Models/
│ │ └── Book.php
│ │
│ ├── Views/
│ │ └── book/
│ │ ├── index.php
│ │ ├── create.php
│ │ ├── show.php
│ │ ├── edit.php
│ │ └── delete.php
│ │
│ └── core/
│ ├── Database.php # Koneksi SQLite
│ └── Helpers.php # Utility functions
│
├── database/
│ └── app.sqlite # File database SQLite
│ └── migrate.php # Script migrasi + seed
│
└── README.md
Semua request HTTP (GET/POST) masuk terlebih dahulu ke file ini.
File ini bertugas untuk:
- membaca query string (?c=controller&a=action)
- menentukan controller mana yang dipanggil.
contoh:
?c=book → BookController
- menentukan method mana yang dijalankan
contoh: ?a=index → index()
Koneksi Database (src/core/Database.php)
Proyek ini menggunakan SQLite sebagai database utama. Jika file database belum ada, maka otomatis akan dibuat.
Migrasi Database
Tidak ada CLI seperti Laravel Artisan.
Migrasi dilakukan dengan menjalankan file PHP biasa:
php database/migrate.php
Perintah ini akan:
- membuat tabel books
- mengisi data awal (seeding)
Inilah alur lengkap dari sebuah request sampai halaman tampil:
- Browser memanggil URL
http://localhost:8000/?c=book&a=show&id=3
- Semua request masuk ke public/index.php
- baca parameter c → menentukan controller
- baca parameter a → menentukan action (method)
- Front Controller memuat file controller yang sesuai
BookController
- Front Controller membuat instance controller
new BookController()
- Action dipanggil
$controllerObj->show();
- Controller memanggil Model
- Model mengambil data dari SQLite
- Mengembalikan hasil ke Controller
- Controller meneruskan data ke View
require Views/book/show.php
-
View merender HTML (menggunakan data yang dikirim oleh controller)
-
Browser menampilkan halaman
Diagram Ringkas
Browser
↓
public/index.php (Front Controller)
↓
Controller
↓
Model ↔ SQLite
↓
View
↓
Browser
Jalankan server PHP bawaan:
php -S localhost:8000 -t public
Lalu akses:
http://localhost:8000
Proyek ini bersifat open-source dan dirilis di bawah MIT License.
Lihat isi lisensinya di sini: LICENSE