ColdMVC

Configuration

You can define configuration variables for your application inside an [INI file] [1] located at /config/config.ini. Each section represents a different environment for your application, with the exception of the default environment, which all other environments inherit settings from.

A typical config.ini file for a blogging application might look like the following:

[default]
controller=blog
sesURLs=true

[development]
development=true
autoReload=true

[production]
reloadPassword=mySecretPassword

Now let's describe the various parts of this parts of this file.

Default Environment

Inside the default environment, we define the name of our application's default controller. In this case, we've set the value to blog. If we were to make a request to our application without specifying a

controller, our application will route the request to the BlogController by default.

We also set a sesURLs property to true. This tells our application not to include index.cfm on any URLs generated by the linkTo or redirect methods. Note: if you enable the sesURLs config setting,

it is up to you to provide the necessary URL rewriting logic inside an .htaccess file or web.config file, depending on which web server you're using.

Development Environment

By setting development to true, we enable a couple convenience options in our application for working in development mode. First, your application's views, layouts, and tags are re-generated each

request, allowing you to see your changes immediately. Second, various internal component caches are cleared each request, such as caches for custom event listeners. Finally, debug information will be append

to the bottom of your view, providing you with access to key information for your request.

Next, we set a autoReload setting to true, meaning the application will be automatically reloaded each request. This is very helpful when in development in order to automatically reload your singleton

components.

Production Environment

In the production environment, we set a variable called reloadPassword to mySecretPassword. The reloadPassword is used when reloading your application through the URL. Be default, you can reload your

application simply by adding an init variable to your URL without specify a password. By setting the reloadPassword to mySecretPassword, you can only reload your application by adding

init=mySecretPassword to your URL. If you would like to change the init variable to something else, simply add a config setting for reloadKey inside your config.ini file with the value of your

choice.

Accessing Config Settings

Your config settings are available to your application in a couple ways.

First, you can access any config setting by using the config helper.

var value = $.config.get("key");

Second, you can inject the config bean into your components.

/**
 * @accessors true
 * @singleton
 */
component {

    property config;

    function sendEmail() {

        if (config.get("allowEmails")) {
            // do stuff
        }

    }

}

Third, you can inject your config settings directly into your singleton beans inside by using the the ${key} syntax inside your /config/coldspring.xml file.

<bean id="emailService" class="app.model.EmailService">
    <property name="allowEmails">
        <value>${allowEmails}</value>
    </property>
</bean>

Finally, you can inject your config settings into your singleton beans simply by naming your keys using a {bean}.{method} syntax. For example, by specifying a config setting of

emailService.allowEmails=true, the bean factory will automatically call the setAllowEmails method on the emailService bean and pass in a value of true when the bean is first constructed.

Complex Settings

You can pass complex values into your beans by using [JSON] [2] syntax for the value of your config setting. The bean factory will automatically convert the JSON string into a complex object before injecting

the property into the component. The following example will inject an array into the setBar method on the fooService singleton bean.

fooService.bar=["boo", "baz"]