Skip to content

Sebuah proyek PHP sederhana tanpa framework untuk mendemonstrasikan arsitektur Front Controller + MVC

License

Notifications You must be signed in to change notification settings

ahmaruff/emvici-php

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mini MVC PHP – Simple Book Management App

License: MIT

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)

Tujuan

  • Belajar konsep dasar MVC tanpa framework
  • Memahami cara kerja routing manual
  • Mengenal pola hubungan antara Controller → Model → View

Stuktur Project

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

Arsitektur Inti (Core Architecture)

Front Controller — public/index.php

Semua request HTTP (GET/POST) masuk terlebih dahulu ke file ini.

File ini bertugas untuk:

  1. membaca query string (?c=controller&a=action)
  2. menentukan controller mana yang dipanggil.
    contoh:
?c=book → BookController
  1. menentukan method mana yang dijalankan
contoh: ?a=index → index()

Database

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)

Flow Request (Alur Kerja Aplikasi)

Inilah alur lengkap dari sebuah request sampai halaman tampil:

  1. Browser memanggil URL
http://localhost:8000/?c=book&a=show&id=3
  1. Semua request masuk ke public/index.php
  • baca parameter c → menentukan controller
  • baca parameter a → menentukan action (method)
  1. Front Controller memuat file controller yang sesuai
BookController
  1. Front Controller membuat instance controller
new BookController()
  1. Action dipanggil
$controllerObj->show();
  1. Controller memanggil Model
  • Model mengambil data dari SQLite
  • Mengembalikan hasil ke Controller
  1. Controller meneruskan data ke View
require Views/book/show.php
  1. View merender HTML (menggunakan data yang dikirim oleh controller)

  2. Browser menampilkan halaman


Diagram Ringkas

Browser
   ↓
public/index.php  (Front Controller)
   ↓
Controller
   ↓
Model ↔ SQLite
   ↓
View
   ↓
Browser

Menjalankan Aplikasi

Jalankan server PHP bawaan:

php -S localhost:8000 -t public

Lalu akses:

http://localhost:8000

Lisensi

Proyek ini bersifat open-source dan dirilis di bawah MIT License.
Lihat isi lisensinya di sini: LICENSE

About

Sebuah proyek PHP sederhana tanpa framework untuk mendemonstrasikan arsitektur Front Controller + MVC

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages