msplus247 / akpan
A lightweight PHP MVC framework.
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:project
Requires
- php: ^8.1
This package is auto-updated.
Last update: 2025-07-15 21:12:35 UTC
README
AkpanMVC is a lightweight, beginner-friendly PHP MVC framework built for rapid development. It supports clean routing, controller architecture, SQL migrations, middleware, and simple view rendering.
๐ Features
- โ
Simple expressive routing (
GET
,POST
) - โ
Middleware support (
auth
,guest
, custom) - โ Controller-based architecture
- โ SQL-based migration system
- โ Blade-like views with data passing
- โ PSR-4 Composer autoloading
- โ
.env
configuration loader - โ Debugging with styled console output
- โ Session-based user auth structure
- โ Auto-loading route/middleware files
- โ Composer ready
๐ฆ Installation
Install AkpanMVC using Composer:
composer create-project msplusapps/akpan myproject
๐ Directory Structure
myproject/ โโโ app/ โ โโโ controllers/ โ Controllers like AuthController.php โ โโโ models/ โ Models like User.php โ โโโ views/ โ Views like home.view.php โ โโโ routes/ โ Route files (web.php, auth.php) โ โโโ middlewares/ โ Middleware functions (auth.php, guest.php) โ โโโ migrations/ โ .sql migration files โโโ core/ โ โโโ Router.php โ โโโ Controller.php โ โโโ Model.php โ โโโ Env.php โ โโโ Database.php โ โโโ Migrations.php โโโ public/ โ โโโ index.php โ Entry point โโโ logs/ โ โโโ error.log โโโ .env โโโ composer.json โโโ README.md
โ๏ธ .env Configuration
DB_HOST=localhost DB_NAME=akpanmvc DB_USER=root DB_PASS=
๐ Routing
Router::get('/', ['WebController', 'index'])->name('home');
Router::get('/login', ['AuthController', 'login'])->name('login'); Router::post('/auth', ['AuthController', 'authenticate'])->middleware('guest');
Router::get('/dashboard', ['DashboardController', 'index'])->middleware('auth');
##๐งโโ๏ธ Middleware // app/middlewares/auth.php function auth() { if (!isset($_SESSION['user'])) { header("Location: /login"); exit; } }
Router::get('/dashboard', ['DashboardController', 'index'])->middleware('auth');
๐งฉ Controllers
class WebController extends Controller { public function index() { return $this->view('home', ['title' => 'Welcome']); } }
Use $this->view('file', ['data' => 'value']) to pass data to views.
๐งฌ Models
class User extends Model { protected $table = 'users'; }
$users = User::all(); $user = User::find(1);
๐ Views
Views are .view.php files stored in app/views/.
Render them from a controller: return $this->view('auth/login', ['title' => 'Login']); Example app/views/auth/login.view.php:
Login๐ Migrations
Add .sql files to app/migrations/.
Example 2024_07_12_create_users_table.sql:
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 ); Migrations are executed once and logged to the msk_migrations table.
๐งช Local Testing
Run the app locally using PHPโs built-in server:
php -S localhost:8000 -t public Then visit: http://localhost:8000
Debugging
Debug output is automatically displayed via Router::debug():
[ROUTE LOADED] app/routes/web.php [DISPATCH] GET '/' [EXECUTE] WebController::index() Errors are saved to logs/error.log for further inspection.
๐ License
AkpanMVC is open-sourced software licensed under the MIT license.
๐ Author
msplusapps GitHub: @msplusapps Packagist: msplusapps/akpan
๐ก Contribute
Fork this repository
Create your feature branch (git checkout -b feature/new-feature)
Commit your changes
Push to the branch
Open a Pull Request
โค๏ธ Thank You Thanks for using AkpanMVC โ weโd love to hear your feedback and ideas!