steevedroz / nano-framework
Requires
- php: >=7.4
- steevedroz/fakedb: ^2.0.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^9.5
README
DISCLAIMER: This is not a good Framework, its sole purpose is the teaching of the mechanisms behind a Framework. For example, the database is simply a bunch of JSON files that have to be completely rewritten each time a single value is edited. Please consider choosing a real framework if you intend to use this as a base for your website.
NanoFramework is an extremely tiny PHP Framework. Its source code holds in 6 classes and 1 dependency. The goal is to stay clear while learning by allowing the student to not be lost in hundreds of source files.
Installation
In order to install NanoFramework:
- Create an empty folder on your computer, where your local server asks you to (usually a directory named
www
orhtdocs
). - From that folder, run the command
composer require steevedroz/nano-framework
(you may need to install composer beforehand). - Run the command
vendor/bin/nano-generate
, accept the override ofcomposer.json
. - Run the command
composer dumpautoload
to reload all the generated files. - Run the website and behold the first page!
Usage
This will explain the basic usage of the Framework. For a more in depth explanation, please consider visiting the doc.
MVC
NanoFramework uses the Model-View-Controller architecture.
The flow is the following:
- The server recieves a request to a URI.
index.php
is called, the route is analyzed.- If the route is referenced in the file called
routes
, it is changed to its corresponding value. - The route (maybe modified) represents the name of a Controller, the name of a method and parameters (parameters are optional, the method is
index
if not specified, only the Controller name is required). - The corresponding method of the Controller is called.
- That method may call a Model, in order to obtain data from the database.
- That method may call a View, possibly passing it the data, in order to generate an HTML file.
- The method returns that file that is bubbled up to
index.php
and displayed on screen.