Copy link to clipboard
Copied
I am wondering how framework one (fw1) making `view()` function available in views , like ColdFusion in built functions?.
For example, in the below code , the `view()` function can be called like any ColdFusion in built functions. How fw1 making it possible?.
#view(‘components/contact’)#
The function `view()` has been defined in /framework/one.cfc
I shall repeat what I said:
Some more code examples, in case you need help to set up a test:
TestComponent.cfc
<cfcomponent>
<cffunction name="init" output="false">
<cfset application.globalView = variables.view>
</cffunction>
<cffunction name="view" output="false">
<cfargument name="callerName
...
Copy link to clipboard
Copied
Yes, you can do that in ColdFusion. Irrespective of whether you're using Framework One or not.
You may store a function, just like any other variable, in application scope. It can then be called from any page in the application.
For example, define the following in one of the CFM pages in Views:
<cfscript>
public string function myView(string caller) {
return "Hello, #arguments.caller# - go view the World!"
}
application.view=myview;
</cfscript>
Now, if you run
<cfoutput>#application.view('BKBK')#</cfoutput>
anywhere in the application, you will get:
Hello, BKBK - go view the World!
Copy link to clipboard
Copied
I think you haven't answer to the question. As I mentioned, view function has been defined in /framework/one.cfc. Still it is available in cfm pages. How it is available in all cfm pages?
Copy link to clipboard
Copied
How it is available in all cfm pages?
By @Abdul L Koyappayil
If you store the function as a variable in application scope, it will be available in all CFM pages of the application. Test the example I gave you, and you will see it for yourself.
Copy link to clipboard
Copied
But the view function is not application scoped in one.cfc right? And since it is not application scoped , how it is accessible in cfm pages?
Copy link to clipboard
Copied
I shall repeat what I said:
Some more code examples, in case you need help to set up a test:
TestComponent.cfc
<cfcomponent>
<cffunction name="init" output="false">
<cfset application.globalView = variables.view>
</cffunction>
<cffunction name="view" output="false">
<cfargument name="callerName">
<cfreturn "Hi, " & arguments.callerName & "!">
</cffunction>
</cfcomponent>
testcode1.cfm
<!---
CFM page is in same folder as the component.
After this line runs, the function View() will be
universally available throughout the application.
--->
<cfset testObject = new TestComponent()>
testcode2.cfm
<!---
Run this page somewhere else in the application,
some minutes later.
--->
<cfoutput>#application.globalView("Abdul L Koyappayil")#</cfoutput>
Copy link to clipboard
Copied
Does that solve your problem? If you have further questions, don't hesitate to ask.