Skip to content

A very simple MVC framework for PHP beginners

License

Notifications You must be signed in to change notification settings

sebapusch/SimpleMVC

 
 

Repository files navigation

SimpleMVC

Build status

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.

ITS ICT Piemonte

Quickstart

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.

Install on Apache

.htaccess file is included to redirect requests to index.php file inside public directory.

Routing system

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.

Dispatch

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);
}

Dependecy injection container

All the dependencies are managed using the PHP-DI project.

The dependency injection container is configured in config/container.php file.

Copyright

The author of this software is Enrico Zimuel and other contributors.

This software is released under the Apache License, Version 2.0.

About

A very simple MVC framework for PHP beginners

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%