The Controller Unit


exports:  class ControllerUnit

class ControllerUnit

extends:  libflitter/Unit

Loads controllers from the specified directory and creates an access function for them. It makes these available as the Controller context and calls the next function in the stack under it.

constructor(String controller_directory = './app/controllers')

overrides:  super.constructor()         returns:  this

Initializes the class. Resolves the fully-qualified path from the provided controller_directory and stores it in

go(express app, function next)

overrides:  super.go()         returns:  undefined

Iterates over files in and retrieves the controller classes from them. Stores them in _flit.controllers.definitions in key-value pairs, where the key is the name of the controller and the value is an instance of the class. The names are parsed from the file names and use Flitter's convention for sub-directory naming. Creates a function to access these instances and makes it available at _flit.controllers.controller(). These establish the Controller context and then the next function in the stack is called under it.


overrides:  super.provides()         returns:  Object

Returns an Object describing the services, templates, and directories provided by this unit. They are as follows:

Type Key Value Notes

Service Name



The name of the service. This is added to the array so other units can check for this unit.
Directory directories.controllers The fully-qualified path of the config files. This is added to the _flit.directories store so other units can access it.
Template templates.controller Object Template that creates new config file in

type:  String

Set on initialization. Specifies the fully-qualified path of the controller class files to be processed. Each of these files should export a class of request-handling methods. Each file's class is assigned a name based on the name of the file it was retrieved from. This includes sub-directories. As is convention in Flitter, sub-directories are delineated with a : character. So a controller class loaded from the file auth/Login.controller.js would be named auth:Login.

Controller Context

This context provides access to instances of the controller classes by name, as well as the global access function, controller().


type:  Object

Holds the variables and functions provided by this unit.


type:  Object

A collection of key-value pairs such that they keys are the names of the controllers parsed from the files in the specified directory. These names follow the Flitter convention for sub-directory naming. The values are instances of the corresponding controller classes.

_flit.controllers.controller(String name)

returns:  mixed

Access function that returns the controller from _flit.controllers.definitions with the corresponding name.

global.controller(String name)

returns:  mixed

Mapped to _flit.controllers.controller().

No Comments
Back to top