Application Structure
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.
config
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
- routes.php
db.json
๐
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 (test
).
For a detailed explanation take a look on
routes.php
๐บ
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:
Controller
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
Middleware
In the 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
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
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.
When the 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.
views
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!๐
More info on that in Views