Next Step (Tahap II – Level Intermediate)
Di tahap ini kita naik level. Kalau Tahap I masih hardcode login, sekarang kita pakai database MySQL + CRUD sederhana biar project mulai terasa seperti aplikasi sungguhan.
1) Login Menggunakan Database MySQL
Buat database baru:
CREATE DATABASE aiticore_project;
Buat tabel users:
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(100),
email VARCHAR(100) UNIQUE,
password VARCHAR(255),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Insert user contoh:
INSERT INTO users (name, email, password)
VALUES ('Admin', 'admin@mail.com', MD5('123456'));
Update AuthController agar cek database via Model.
$user = $userModel->findByEmail($email);
if ($user && $user['password'] === md5($password)) {
$_SESSION['user'] = $user;
header("Location: /dashboard");
exit;
}
Catatan: Tahap belajar boleh pakai MD5. Produksi? Wajib pakai password_hash().
2) CRUD Sederhana (Contoh: Produk)
Buat tabel products:
CREATE TABLE products (
id INT AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(150),
price DECIMAL(12,2),
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Routing CRUD
$router->get('/products', 'ProductController@index');
$router->get('/products/create', 'ProductController@create');
$router->post('/products/store', 'ProductController@store');
$router->get('/products/edit/{id}', 'ProductController@edit');
$router->post('/products/update/{id}', 'ProductController@update');
$router->get('/products/delete/{id}', 'ProductController@delete');
Contoh Method Store
public function store()
{
$name = $_POST['name'];
$price = $_POST['price'];
$this->productModel->insert([
'name' => $name,
'price' => $price
]);
$_SESSION['success'] = "Produk berhasil ditambahkan.";
header("Location: /products");
exit;
}
3) Flash Message + Redirect Proper
Di view products:
<?php if(isset($_SESSION['success'])): ?>
<div class="alert-success">
<?php echo $_SESSION['success']; unset($_SESSION['success']); ?>
</div>
<?php endif; ?>
Ini bikin UX naik level. User dapat feedback setelah aksi.
4) Logout + Middleware Auth Sederhana
Routing Logout
$router->get('/logout', 'AuthController@logout');
Method Logout
public function logout()
{
session_destroy();
header("Location: /login");
exit;
}
Middleware Auth (Sederhana)
if (!isset($_SESSION['user'])) {
header("Location: /login");
exit;
}
Nanti bisa dibuat middleware class terpisah supaya lebih clean.
Kenapa Tahap II Ini Penting?
- Kamu mulai ngerti alur Database → Model → Controller → View
- Kamu paham session lifecycle
- Kamu belajar CRUD dari nol
- Kamu siap bikin mini sistem POS / blog / inventory
Di titik ini, AitiCore Flex sudah bukan cuma bahan belajar — tapi sudah bisa jadi pondasi aplikasi real kecil sampai menengah.
Selanjutnya (Tahap III – Mini Project Real)
- Mini Blog System
- Mini POS sederhana
- Role-based login (Admin / Staff)
- Template layout reusable
Semoga Bermanfaat.