A lightweight PHP micro-framework based on the MVC architecture. It features routing, request/response handling, a simple ORM, middleware support, and environment-based configuration. Designed for building clean, maintainable web applications.
- MVC (Model-View-Controller) structure
- Routing system
- Request and Response handling
- Simple ORM for database operations
- Middleware support
- Environment configuration via
.env
composer.json
.env.example
config/
config.php
public/
index.php
core/
App.php
Router.php
Request.php
Response.php
Controller.php
View.php
Model.php
Database.php
ORM.php
src/
MiddlewareInterface.php
AuthMiddleware.php
app/
Controllers/
HomeController.php
Views/
home.php
-
Clone the repository:
git clone https://github.com/robycinix/php_mvc_framework.git
-
Navigate into the project directory:
cd php_mvc_framework -
Install dependencies using Composer:
composer install
-
Set up your environment file:
cp .env.example .env
-
Configure your database settings in
config/config.phpand.env.
- Start your local development server:
php -S localhost:8000 -t public
- Visit
http://localhost:8000in your browser.
In routes/web.php (or directly in the Router setup):
$router->get('/', 'HomeController@index');In app/Controllers/HomeController.php:
<?php
namespace App\Controllers;
use Core\Controller;
class HomeController extends Controller
{
public function index()
{
return $this->view('home', ['message' => 'Welcome to the PHP Micro-Framework!']);
}
}In app/Views/home.php:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Home</title>
</head>
<body>
<h1><?php echo \$message; ?></h1>
</body>
</html>Configure your database credentials in .env and use the Model class to interact with the database.
Example usage in a Model:
<?php
namespace App\Models;
use Core\Model;
class User extends Model
{
protected \$table = 'users';
}- PHP >= 7.4
- Composer
This project is licensed under the GNU General Public License v3.0 (GPLv3).
Feel free to contribute and improve this framework! Created by Roby.