James A Mohler
James A Mohler

Reputation: 11120

Variables. scope inside of a cfmodule

I have a page with a name of

summary.cfm

inside of it:

 <cfinclude template="view/totals.cfm>

view/totals.cfm

inside of it:

variables.grandTotalHTML = invoke("viewtotals, "doSummary", {...});

view/viewtotals.cfc

inside of it

<cfmodule template="summarytemplate.cfm" ...>
<!--- database is not passed in here --->

view/summarytemplate.cfm

Inside of it we have

param attributes.database = session.database;
...
databaseoverride = attributes.database;
...

<cfquery name="qData">
   SELECT *
   FROM [#variables.databaseoverride#]
   ...
</cfquery>

Now question

I don't know where the databaseoverride is coming from.

  1. Does global page request scope?
  2. Does it come from variables in viewtotals.cfc ?
  3. Does the unscoped version override it?

Upvotes: 1

Views: 344

Answers (2)

SOS
SOS

Reputation: 6550

(Too long for comments)

Just to elaborate on Dan's answer:

summary.cfm

  • Only shares a VARIABLES scope with the included template, "view/totals.cfm"

view/totals.cfm

  • Only shares a VARIABLES scope with the parent template, "summary.cfm"

view/viewTotals.cfc

  • Its VARIABLES scope is not shared with any of the calling templates (summary.cfm and view/totals.cfm)

  • Its VARIABLES are accessible to the cfmodule - through the CALLER scope (as are the function's local and arguments scopes)

view/summaryTemplate.cfm

  • Does not share its VARIABLES scope with anyone.
  • Can view/modify any scopes in the parent component (viewTotals.cfc) through the CALLER scope.

( The REQUEST scope is accessible to all of the scripts above.)

Upvotes: 1

Dan Roberts
Dan Roberts

Reputation: 4694

The variables scope at the module level is local to the module. An unscoped variable in a module is in variables scope.

This line

databaseoverride = attributes.database;

is equivalent to

variables.databaseoverride = attributes.database;

so is setting the value used here

<cfquery name="qData">
   SELECT *
   FROM [#variables.databaseoverride#]
   ...
</cfquery>

Upvotes: 2

Related Questions