Fork me on GitHub

Nibble Development

Nibble Development

PHP classes and libraries for developers

Bites directory structure and configuration

All bites follow a set directory structure. This structure must be followed for the Nibble PHP Framework to recognise, install and run a Bite (obviously the order of the sub directories is of no relevance, just that they all exist):

Each of the above directories can have the following files:

  1. Your Bite main directory: This directory has the controller files and the configuration file for the Bite. The controller files are called actions.appname.class.php where appname is the name of the application that you want the controller to be called for (like frontend or admin).
  2. Forms: This directory contains any forms files made using the Nibble Forms class.
  3. Graphic: This directory contains any graphic files that the Bite needs access to in the web/graphic directory.
  4. Partials: This directory contains any partials. Partials are files that are included in views to produce duplicate content such as table rows are required. Partials are named partialname.appname.php where partialname is the name of the partial called by the render->partial() method, and, appname is the name of the app that the partial should be called in. I.e admin partials will not be called when the frontend app is running.
  5. Script: This directory is the same as the graphic directory but for script files.
  6. Style: Same again as script and graphic but for css files.
  7. Views: This directory contains all view files. Views are named, appname.viewname.php where appname and viewname are the same as appname and partialname in the partials directory.

The configuration file

The configuration file, config.php, sets up all the local settings for the Bite. These settings include variables that inform the system which scripts and styles to include on a page, installation properties, Other Bites that your Bite is dependent on and navigation properties. Below is the config.php file for the default Bite that comes with the Nibble PHP Framework:

All of the above variables should be present in your Bites config.php file, however it is perfectly fine just to have them as empty arrays if you have nothing to specify. Each variable has its own specific function that hopefully should be quite logical:

$script: This array allows JavaScript files to be assigned to certain actions. This example shows that the managePlugins action should have bites.js included in the head of the page. The key “all” can be used to specify an array of JavaScript files that will be used for all actions in the Bite.

$gjs: Gjs stands for Google JavaScripts which refers to any scripts that are provided by the Google Libraries API. This array functions much like the $script array allowing scripts to be allocated to individual or all actions. Each script requires two arguments, the name of the JavaScript as it appears in the API call, and the version number of the script to get. The “1″ as the version number argument for JQuery refers to version 1.x.x where x is the most recent version sourced by Google.

$style: This array is works exactly the same as $script but is for including style sheets. For example:

$install: There are three key value pairs in this array that are used when the Bite is first installed and to check that the database tables exist for it.

  1. The first value “desc” is the description of the Bite that will appear in the Bites management page when users want to activate or de-activate it.
  2. The “table” attribute references the main database table for the Bite. Only one table name is required as this value is used to check that the database schema file has been run.
  3. The third attribute “type” refers to the level of the Bite. This value can be any of the number 1 – 3 where 1 = Global Bite, 2 = Full system Bite, and, 3 = Additional functionality Bite.
  4. If the Bite type is 3, a fourth attribute is required called “extends”. This attribute refers to the Bite that the your Bite extends (adds functionality too). For example our Bite extends the “blog” Bite, thus we need the key, value pair:  "extends" => "blog"

$dependencies: This array informs the system of the Bites that must already be active before your Bite can be activated. The example above has the value “none” which means there are no dependencies. If your Bite required that the user and blog Bites be active the code would look like:

$navigation: The final array is used if automatic navigation is being used. Each new depth of the array after the first adds a new tier of navigation. The first level keys refer to the application that the navigation should be generated for. Thus “frontend” means the array value pointed to will only be generated in the frontend application. The second set of key, value pairs provide the navigation system with anchor text and href values respectively. If a second tier of navigation is required for a particular key, the value should be an array of key, value pairs and the last array item should be the href value of the parent key:


Luke Rotherfield

Freelance PHP Developer
is a PHP developer dedicated to writing the most awesome liraries for his fellow devs :) enjoy

Latest posts by Luke Rotherfield (see all)

Leave a Comment