Search code examples
scopecoldfusioncfccoldfusion-2016

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?

Solution

  • (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.)