Question

I'm learning the FW/1 framework and so far so good. I understand mostly how controllers/services/views work. However I have some additional functions that manipulate the views in some cases i.e. alter the CSS and layout depending on what is returned to the view. Where is the best place to add this functions to make them accessible by the view?

Was it helpful?

Solution

To use an example, I typically will use a 'formatter' object - for formatting dates, etc. consistently in my applications. To accomplish this in a FW/1 app I have typically have a controller method I call in setUpRequest() that will put the formatter object into the request context (rc).

For example, My setupRequest() method may look like this

function setupRequest( rc ) {
    controller( 'setup.default' );
}

And in setup.default() I would have code similar to this:

component accessors="true" {

    property Any formatter;

    public void function default( Any rc ){
        rc.formatter = formatter;
    }
}

I use ColdSpring to handle my dependency injection - but I am pretty sure you can just as easily use DI/1 and not have any of this code change at all.

Then, for example, if I need to format a date in a view, I simply use this:

rc.formatter.formatDate( someObject.getSomeDate() )

You could modify this example to use different logic for your CSS, etc., put that logic into a CFC and include it in the request context (rc).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top