Skip to content

Configuration

Jerome Lepage edited this page Oct 11, 2016 · 9 revisions

Basic configuration

On your Application.cfc you should have a setParams() function for perfectly set your application.
In this purpose, you can define a parameter easly just by calling this function :

addParam('myParameter', 'myValue');

You can also override default configuration in the same way.
(TODO: add the list of parameters from default configuration)
See Default parameters section for more informations

Environments configuration

An environment is referering to your hosting environments.
You surely want to configure once at all parameters whatever they are for development, test or production.
With cfFramework is easly to set up.
Remember that the environment is only setup once at startup and never change (unless you'r reloading app).

Define Environments

You must define a rule (or more) for detecting your environment (by default is "debug").

addEnvRule( new cffwk.base.conf.elements.SimpleEnvRule(hostname = 'localhost', name = 'debug') );
addEnvRule( new cffwk.base.conf.elements.SimpleEnvRule(ip = 'x.x.x.x', name = 'debug') );

Rules must be a implementation of "cffwk.base.conf.elements.EnvRuleInterface", so you can use SimpleEnvRule of cfFramework or create your own.
SimpleEnvRule must be initiated with a name and a hostname or an ip.

Define Environment Parameters

You can easly set parameters for a specific environment like this :

addParamByEnv('debug', 'myParameter', 'debugValue');
addParamByEnv('prod', 'myParameter', 'productionValue');

Is pretty easy, isn't it ?

Contexts

A context is a name determined by some (http) resquest rules. So it will be redetected on every requests.

Configure contexts

You can add a context just by adding a rule with the addContextRule funtion on Application.cfc.
ContextRule must be an implementation of "cffwk.base.conf.elements.ContextRuleInterface" so you can use SimpleContextRule of cfFramework or write your own rule(s).
SimpleContextRule expect a name and a hostname or an uri to work.

addContextRule( new cffwk.base.conf.elements.SimpleContextRule(hostname = 'cfframework.local', name = 'full') );
addContextRule( new cffwk.base.conf.elements.SimpleContextRule(hostname = 'cfw.local', name = 'short') );

Routes

A route is an association of parameters to determine on an URI pattern, which function on which controller will respond to the request.

You set a route by calling the addRoute() function of Router object.

getRouter().addRoute(id='home', route='/home', controller='DefaultCtrl', action='home');

id: is the name of the route route: is the URI pattern. Parameters could be un URI with brackets (see sample below) controller: is your controller object (be in mind that it will be a singleton) action: is the callled function on your controller

A parameter example :

getRouter().addRoute(id='productView', route='/product/{id}', controller='ProductCtrl', action='viewObject');

Which will call, on a /product/123 request,

ProductCtrl.viewObject({id= 123}); 

On views you can create an URL by calling getURL function :

getURL('productView', {id= 123});

Clone this wiki locally