The main purpose of this project is to learn and understand MVC architecture in PHP. The code is written to be as clear and simple as possible, making it easy for newcomers to follow and experiment.
SuperSimpleMVCPHP/
├── app/
│ ├── controllers/
│ ├── core/
│ ├── models/
│ └── views/
├── public/
│ └── index.php
├── .htaccess
└── README.md
public/index.php
– Entry point of the application (bootstrap)core/
– Core classes: App (router), Controller (base controller)controllers/
– Your controller classes (e.g., Home.php)models/
– Data access logicviews/
– HTML rendering files
- Clone the repository:
git clone https://github.com/ifet4u/SuperSimpleMVCPHP.git
- Start the built-in PHP server:
cd SuperSimpleMVCPHP/public
php -S localhost:8000
- Open in your browser: http://localhost:8000
The application's entry point. Loads the App
class and starts routing based on the URL.
Parses the URL and dynamically calls the corresponding controller and method.
Example URL:
/home/about
→ Calls the Home
controller and its about()
method.
class Home extends Controller {
public function index() {
$this->view('home/index');
}
}
Views are simple .php
files located in the app/views/
directory. You can pass data from the controller to the view using an associative array.
Controller:
class Home extends Controller {
public function index() {
$data = [
'title' => 'Welcome Page',
'message' => 'Hello from the controller!',
'users' => ['Alice', 'Bob', 'Charlie']
];
$this->view('home/index', $data);
}
}
View (app/views/home/index.php
):
<h1><?php echo $title; ?></h1>
<p><?php echo $message; ?></p>
<ul>
<?php foreach ($users as $user): ?>
<li><?php echo $user; ?></li>
<?php endforeach; ?>
</ul>
The view()
method automatically extracts the array into variables, so you can use $title
, $message
, or even loop through $users
directly in your view.
You can pass both single values and arrays, depending on what your view needs to display.
URL: /home/hello/Marko
Controller method:
public function hello($name = '') {
echo "Hello, $name!";
}
- This project is not suitable for production — it lacks protections like SQL injection prevention, CSRF, XSS, etc.
- There's no session management, authentication, or templating engine — it's built to stay as minimal as possible for learning purposes.
If you'd like to improve this educational project:
- Fork the repository
- Create your branch (
git checkout -b feature/your-feature
) - Submit a pull request
Special thanks to Dave Hollingworth (GitHub profile), whose tutorials and teaching style greatly helped shape this project and made learning MVC in PHP much easier.
The name SuperSimpleMVCPHP is a nod to Super Simple Songs, whose approach to learning — simple, clear, and effective — inspired the naming style of this project. While the content is entirely different, the philosophy of making learning easy and enjoyable is shared.
MIT License — free to use, modify, and distribute for educational purposes.
Author: ifet4u
Feel free to reach out if you have questions, suggestions, or want to use this in your course or classroom.