Minimalistic framework for php.
You might think: why would someone build a new framework as there are plenty of good, opensource frameworks out there. And yes you are right, but I've read somewhere (cannot remember where), that every developer should write their own framework: not necessarily to use it or release it, but to learn from it. And the article was right, it is a interesting challenge and a useful experience.
- Make a copy the
config/env.default.php
asconfig/env.php
, and set up the database parameters - Create the database and run the sql dump:
db/test.sql
- Set up the web server to route all requests through
index.php
For example the Nginx config will look like below:
location / {
try_files $uri $uri/ /index.php?$query_string;
}
- Run
composer install
to install PHPUnit
The routes can be set up in config/Routes.php
, separately for get and post requests.
The Core/Router class is responsible for parsing the url,
and the Core/Dispatcher class instantiates the controller and invokes the
corresponding action, passing the get or post parameters as the first argument
to the action method.
The Core/View class handles view data, and renders the templates. The template for the main layout can be found in views/layout/main.php
The Models/Model class represents the abstraction layer for the database. Currently it only supports insert and select statements, using only simple equal conditions in the where clause.
The application uses the composer autoload function for loading classes from vendor files, and also for loading it's own classes.
Tests can be run manually by using PHPUnit: vendor/bin/phpunit
,
and Travis CI is used for running test automatically after each push.
The validation of form fields is missing completely... Only the "required" attribute have been added to some of the inputs.
Add support for update, delete queries, and for more sophisticated select queries.
The database abstraction layer could be moved to database drivers, to support multiple databases (PosgreSQL, MySQL, Oracle, etc...)
Error handling could be improved in general.
- PHP7
- Mysql
- Web server: Apache or Nginx