Folder Structure
A Haplo Framework install contains the following directories:
- actions - Put action/controller classes here. The framework ships with two example actions (one for managing static pages and another for providing 404 functionality).
- cache - Cached data is stored here, such as parsed translation files. If you're using a caching library, such as the included file cache, it's cache files should also be stored here.
- config - Contains base configuration for Haplo Framework. You can also add your own configuration files here for use in your application. Files use the "INI" file format and are processed alphabetically. Duplicate keys in subsequent files override those found in earlier files.
- custom-template-functions - A place to store custom functions for use in templates.
- haplo-framework - Contains core framework files. If possible you should avoid changing these to ensure an easy upgrade path in the future.
- includes - A place to store your library code. This directory is not directly used by the framework.
- models - A place to store your models. The framework does not enforce any particular structure for models or a database layer. You're free to choose a third party ORM such as Doctrine, Propel, Outlet, a database abstraction layer such as PDO or a native DB library such as mysqli.
- post-filters - A place to store post filter functions which can be run against template output.
- templates - Contains your templates. You can create sub directories to enable organisation of a large number of templates. Templates use PHP for the template language.
- translations - Contains language files. These files can be arbitrarily named, although I usually use ISO language codes such as en_UK.
- www - Contains "index.php", "CSS", "images" and "JavaScript" files. This directory should be set as your web server's document root and you should ensure that it's the only one that's publicly accessible.
Processing Steps
When a request is made to an application written using the Haplo Framework the following steps take place:
- The "index.php" file is run.
- It runs a simple set up check that reports any problems with the installation. This is pretty lightweight but can be disabled if required.
- Next Haplo Framework files are included and an instance of the config object is created which processes any configuration files stored in the "config" directory (files must end with .ini).
- An instance of HaploRouter is then created which tries to match the request URI against an array containing URL pattern to action mappings. As soon as it finds a match it returns the appropriate action name.
- "index.php" then includes the corresponding action file.
- Action files can contain straight PHP or a class which extends HaploAction. HaploAction provides a number of helper methods for running code depending on the request method (GET, POST etc) as well as providing hooks for form validation success and failure.
- If a class that extends HaploAction is found, "index.php" will create an instance.
- Action files should contain code for retrieving data from models and combining with templates to create finished pages. They should also contain any validation code required by your application.
- Whilst rendering templates any custom template functions referenced will be run.
- The HaploTemplate class provides methods for specifying post filter functions. These can modify the generated template output.