Gallery3:Developer Handbook:Framework - Gallery Codex
Personal tools

Gallery3:Developer Handbook:Framework

From Gallery Codex


Gallery 3 is built on top of Kohana 2.3, a lean and fast application framework. Some of the design concepts below are similar or identical to the way that Kohana works. As a result, almost all of the well documented Kohana 2.x APIs are available to the Gallery 3 module and theme developer. New developers are encouraged to familiarize themselves with the APIs that Kohana makes available.

Gallery 3 has the following top level structure:

  • application - This is a minimal Kohana application that is a wrapper around Gallery. It’s required by Kohana, but serves little purpose except to bootstrap Kohana.
  • system - This is the Kohana framework code and core libraries.
  • modules - These are individual Gallery 3 modules. The core Gallery 3 application is located in modules/gallery and it loads up any other Gallery 3 modules that are installed and activated.
  • themes - These are individual Gallery 3 themes. The gallery module loads the appropriate theme based on the user request.
  • lib - Gallery 3 specific common Javascript and CSS libraries used by modules and themes
  • installer - Gallery 3 installer. This is a mostly separate code base designed to bootstrap the initial install of Gallery 3.

Kohana is an opinionated framework. There is a right way to write the code and if you do it that way, then it's very easy and you don't have to write much code. One way that you'll see this is that Kohana expects certain files to be in certain places. A fully fleshed out example module would have this directory structure:

 ├── config 
 ├── controllers
 ├── css
 ├── helpers
 ├── hooks
 ├── images
 ├── js
 ├── libraries
 │   └── drivers
 │       └── ExampleDriver
 ├── models
 ├── tests
 └── views

Very few modules need this many directories! If you don't have any controllers, you wouldn't bother to create a controller directory. But if you do have a controller and you put it in the controllers directory then Kohana knows exactly where to look for it. This means that you don't have to do anything other than write a few lines of controller code then name and place the file the right way and Kohana will immediately start using it. In Kohana, this feature is known as the Cascading File System, and it allows most modules to remain relatively small because they contain little to no boilerplate code.