File structure
It is a good practice to standardize the file structure of projects. This way it’s easier to keep a clean overview of multiple projects, and less time is wasted trying to find the correct class.
When using DotKernel 3 the following structure is recommended:
Main directories
src
- should contain the source code filestemplates
- should contain the page templates and layoutsdata
- should contain project-related data (AVOID storing sensitive data on VCS)docs
- should contain project-related documentation
These directories reside in one of the following directories:
- if the Module is a composer package where the directories above are stored in the package’s root path, eg.:
/vendor/my-name/my-project-name/
- if the Module is an extension/component for the project, eg.:
/src/MyProjectName
The src
directory
This directory contains all source code related to the Module. It should contain following directories, if they’re not empty:
Action
- Action classes (similar toControllers
but can only perform one action)Authentication
- For authentication related classesController
- For controllersEntity
- For entitiesFactory
- Factories (what is a Factory?)Mapper
- Mappers (What is a Mapper?)Service
- Service classes (what is a Service?)
The above example is just some of the directories a project may include, but these should give you an idea of how the structure should look like.
Note: Other classes in the
src
directory may includeInputFilter
,Validator
,Decorator
,Wrapper
,Helper
,Hydrator
.
Classes can be distributed by their entity too. Eg.: User
- user related classes.
This is useful when working on very small projects which have only one class of each kind. Eg.: UserMapper
, UserValidator
, UserHydrator
, etc.
The templates
directory
This directory contains the templates.
Note: DotKernel3 uses twig as
Templating Engine
. All template files have the extension.html.twig
app
- application-specific templateserror
- error message templateslayout
- page layout (page structure)page
- static page templatespartial
- “page components” - blocks that can be included on any page (such as alerts, form display, navigation, side menus, etc)
Note: Unlike some templating engines, Twig will not parse PHP in the template, should you wish to use PHP, you should instead create a Twig extension, or do the PHP relating actions in beforehand, and include the variable when displaying the template.
The data
directory
This directory contains project-related data (such as cache, file uploads)
We recommend using the following directory structure:
data
- general project data or project initial data like database structuredata/cache
- for caching purposesdata/uploads
- for file uploadsdata/proxies
- for class proxies
This page was generated by GitHub Pages.