In ColdFusion, how do you explicitly reference the

2019-07-21 05:43发布

Is there a way to explicitly reference the THIS scope defined in Application.cfc?

Say I have an Application.cfc like this:

component {
this.name="MyApplication"
..

I know that from any page in the site, you can access this.name this way...

<cfoutput>#this.name#</cfoutput> 

...but if you are in another component, how would you reach the Application.cfc's "this" scope? Is it possible without handing the var off?

Adobe documentation says that you can reference the "THIS" scope by using the instance or object name as a prefix. I tried Application.this.name but it didn't work.

1条回答
三岁会撩人
2楼-- · 2019-07-21 06:17

Most of the things that are set in "this" in Application.cfc are not accessible outside the execution of it. ColdFusion copies this.name into application.name at runtime, so you can access application.name from anywhere in your application. For the other settings in "this", they appear to be accessible from your pages because the pages are included into the application.cfc execution cycle by the OnRequest() method.

Once you instantiate a CFC and work inside it's methods, the context of "this" changes to the constructor of that CFC.

查看更多
登录 后发表回答