SimpleMVC is a micro MVC framework for PHP using FastRoute, PHP-DI, Plates and PSR-7 standard for HTTP messages.
This framework is mainly used as tutorial for introducing the Model-View-Controller architecture in modern PHP applications.
This project is used for the course PHP Programming by Enrico Zimuel at ITS ICT Piemonte, an Higher Education School specialized in Information and communications technology in Italy.
You can install the SimpleMVC framework with the following command:
composer create-project ezimuel/simple-mvc
This will create a simple-mvc
folder containing the skeleton of a simple web application.
You can execute the application using the PHP internal web server, as follows:
php -S 0.0.0.0:8080 -t public
You can see the application at the following url: http://localhost:8080.
The routing system uses a PHP configuration file as follows (config/route.php):
use SimpleMVC\Controller;
return [
['GET', '/', Controller\Home::class]
];
A route is an element of the array with an HTTP method, a URL and a Controller class to be executed. The URL can be specified using the FastRoute syntax syntax.
The dispatch selects the controller to be executed according to HTTP method and URL. The dispatch is reported in public/index.php front controller.
A controller implements a ControllerInterface
with one function execute($request)
, where $request
is PSR-7 ServerRequestInterface
, as follows:
namespace SimpleMVC\Controller;
use Psr\Http\Message\ServerRequestInterface;
interface ControllerInterface
{
public function execute(ServerRequestInterface $request);
}
All the dependencies are managed using the PHP-DI project.
The dependency injection container is configured in config/container.php file.
The author of this software is Enrico Zimuel and other contributors.
This software is released under the Apache License, Version 2.0.