A lightweight, docker ready Model View Controller (MVC) template using PHP 8.4 (Apache).
- CSRF Token
- Auto-loader
- Fully automated router
- View rendering engine with data injection
- Config file to easely change the project behavor
- CSS Light/Dark mode linked to system color scheme
- Exemple API controller (with exemple json data/fetchs in js)
- Some PHP/OOP Concept
- Docker & Docker compose (Docker compose is now integrated to docker)
- WSL 2 for Windows users only
docker-compose up -dYou are now ready to go !
- Your controller/view names NEED to begin with a capital letter and end with the word
VieworController- For exemple, a view and a controller for your "home" page should be named
HomeViewandHomeController
- For exemple, a view and a controller for your "home" page should be named
-
Controller Resolution
- The first URL segment (e.g.,
/home) is used to determine which controller to use for the page, in this case,HomeController
- The first URL segment (e.g.,
-
Method invocation
- The second segment of the URL, if it exists, is used as the method to invoke, for example,
/home/testwill call thetestmethod of theHomeController(if it exists). - Any remaining URL segments (if any exists) will be passed as arguments to the invoked method.
- The second segment of the URL, if it exists, is used as the method to invoke, for example,
For the url http://localhost/template/testFunction/arg1/arg2
The router will instanciate the template controller (first url segment), which will create our template view.
The router will then call the template controller's testFunction (second url segment) and pass arg1 and arg2 as function's arguments (you can pass none or as many arguments as you want !)
- Our
.htaccessfile (located in our/publicdirectory) will rewrite our current url to our entry file (which ispublic/index.php) and will pass all our url segments as an url parameter.- So the url
http://localhost/home/test/argwill becamehttp://localhost/index.php?p=/home/test/arg.
- So the url
- Our entry file (index.php) will then instanciate our Router which will parse our url parameter
pas described in the Quick summarize.
To include other directory to the autoloder, you cn simply add theme to the $directory array of the src/core/Autoloader.php file.
$directory = array(
'core/',
'models/',
'controllers/'
);- Use namespaces and PSR-4 autoloading
- Add flash messaging or error reporting to views
- Integrate unit tests
- More secured API ?
This project is licensed under the MIT License © 2025 Gersigno.
For support, email contact.gersigno@gmail.com or join the discord server.