Yet another simple MVC PHP framework
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


A simple MVC framework written in PHP. Name was inspired by Megumin from Kono Subarashii Sekai ni Shukufuku wo! anime :)

Name inspired by Megumin from Kono Subarashii Sekai ni Shukufuku wo!


A main purpose of this project is to easily start a new project codebase using set of base classes and tools that are intended to make your work faster and keep the code clean.

Despite of mainstream PHP frameworks, this one provides only the most common components, such as:

  • Dispatcher - performs routing to the controllers (with friendly URLs support)
  • ModelFactory - manipulates Model storage by queries (SQL databases)
  • Model - represents some data in project, such as UserModel, PostModel or so..
  • Controller - handles data from inputs, manipulates on Models and presents results to user
  • View - presents data from isolated variable scope on page

There are also basic implementations of some classes:

  • MySQLModelFactory - ModelFactory that handles custom MySQL queries to retreive and manipulate data
  • ScopeDebugView - View that displays informations about controller - can be used for debugging


You only need to add new dependency to your composer.json file:

  "require": {
    "pfcode/megumin-framework": ">=1.0.0"

...and update your project (Composer should automatically download latest package):

composer update

Quick Start

There's a sample index.php in examples directory that uses MeguminFramework and performs sample routing. Here is the basic part of it (assuming that sample controllers have been defined and autoloaded)


// Use MeguminFramework namespace to gain direct access to its components
use pfcode\MeguminFramework\Dispatcher;
use pfcode\MeguminFramework\View;

// Use PSR-4 autoloader generated by composer
require __DIR__ . "/../vendor/autoload.php";

// Set global View parameters (page title doesn't have to be honored by chosen View)
View::setPageTitlePrefix("Website Title");
View::setPageTitleSeparator(" : ");

// Specify namespace that your controllers belongs to 

// Set controllers that should be called when routing fails
Dispatcher::setFallbackControllers(DashboardController::class, NotFoundController::class);

// Specify routing table for the dispatcher 
// (you can omit this call when you don't want to use friendly URLs)
    "/test/{id}" => TestController::class,
    "/test" => TestController::class,
    "/" => DashboardController::class

// Perform routing and execute proper controller