msplus247/akpan

A lightweight PHP MVC framework.

v1.0.0 2025-07-13 04:34 UTC

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!