When we start with a new FMVC project, we can use either the CLI or compy an empty project. The resulting structure will look like this:
This may seem a little much at first glance but we will walk through the structure step by step and look on the whats and whys of it.
The first directory in our list is called
config in this folder all configuration should reside.
Right now there are only two files in here:
db.json stores all information about our database connections. Right after creation it looks roughly like this:
It holds two default connections used to provide a data connection for development (
default) and for testing (
For a detailed explanation take a look on
A bit unconventional is the other file in the
config directory: routes.php.
When developing applications with FMVC, every request will be redirected to
index.php. Here the router will check
routes.php for the way it should handle requests.
Here's an example
The routes file exports an associative array where the keys represent the route, that is being handled, and the value represents an array containing the handling configuration:
This folder holds the application controllers. A controller is an encapsulated entity, providing methods to handle requests.
More information about controllers and how to use them can be found here
Core classes of the FMVC framework. This folder will in future versions be moved into
vendor and made available as a composer package.
For a look into the dark and ugly interiors of FMVC take a look at the GitHub repository!
Middleware directory resides all middleware available to the application. When middleware is configured for a route, the framework will take a quick look into the directory and load the corresponding class.
An introduction to middleware and how FMVC uses it, refer to Middleware.
test - as the name already spoils - contains the unit tests for your application. Right now the components for making testing easier are still in development 👷🏗.
But when everything's finished, the guide will reside here!
Validation of a data structure is a big issue in every application. Fortunately, FMVC can draw on DRY::PHP. DRY::PHP is a validation library for objects as well as arrays.
validation key is set in a route configuration, FMVC will search in this directory for the specified class.
More on validation and how it is being used here.
Sometimes we want to render complex HTML views and send them as a response to the client - in the past this has proven as a solid practice when creating application for web browsers. So when you want to get really freaky, this folder will hold all your templates!😏