CFWheels - Should I Locally Locate My Wheel Actions?

Let's say I have such a simple controller:

<cfcomponent extends="Controller"> <cffunction name="hello"> <cfset time = Now()> </cffunction> </cfcomponent> 

In direct ColdFusion / Railo, I would locally look at all the variables in this ... but every wheel example that I see does not.

This will probably earn me the dumbest reward question of the year, but I thought about that because no one ever shows their Wheel Code correctly?

I would write it as follows:

 <cfcomponent extends="Controller"> <cffunction name="hello"> <cfset local.time = Now()> </cffunction> </cfcomponent> 

I'm just not sure that Wheels may be doing something to fix it independently, and why do I see what I'm doing everywhere ... or is it just bad programming?

Thanks! Mikey

+4
source share
2 answers

Yes, you should view it .

In the first example, in most cases you set variables.time , which is local to the component instance, and not to the function - if it is intended as a local variable function (i.e. local.time ) but is in the component variable area, and this component is general / permanent, it can cause problems (although, perhaps, those that appear only under heavy load).

If you place a variable in the scope of variables, it must be explicitly limited (like variables.time ), otherwise it can cause problems when using on the Railo server with the localmode parameter enabled.

Due to cfWheels constructive solution (see links in comments), so that variables in the variable area are necessary for passing variables to the view, even if they can be technically local to the function / view, (The controller instance lives on a single request, avoiding problems. which this usually entails.) As mentioned in the previous paragraph, the local mode parameter (described below) means that it is still recommended to explicitly have it when you do not control all the servers the code will be deployed to.

Setting Railo Local Mode

Railo (since v1) has an administrator parameter called "localmode", which determines whether the assignment of a variable without a space will go to the local region, and not to the region of variable components, which makes explicit the var / local region is not required (if you know your the code will only run on Railo servers with the option enabled).

Since this setting is disabled by default, and ColdFusion does not have this setting, cross-engine support code should always have such assignments so that this is not a problem.

+8
source

It depends. If you want the variable to appear in the view, apply it to the variables. If you want the variable to be only in the controller, specify it locally.

+4
source

All Articles