Render JSON from controller method

108 Views Asked by At

I'm on FW/1 4.2. The documentation states the following:

You can return data directly to the caller, bypassing views and layouts, using the renderData() function.

variables.fw.renderData().data( resultData ).type( contentType );

When I attempt to use variables.fw.renderData() in my controller function, I get the following error:

Component [controllers.notifications] has no accessible Member with name [fw]

If I dump the variables scope, the only thing in it is the controller methods themselves. There is no fw object in the variables scope. I installed FW/1 using the commandbox CLI.

Everything else appears to be working fine (routing/etc). Why is the fw object not available to my controllers?

1

There are 1 best solutions below

0
On BEST ANSWER

You'll need to define variables.fw to the component scope.

public any function init( fw ){
    variables.fw = fw;
    return this;
}

Variables inside a component behaves different than in regular cfm pages. Inside a component variables scope holds the properties of the components such as member functions and other defined properties.