• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How ColdFusion framework ONE making view function available in views

Community Beginner ,
Jul 21, 2021 Jul 21, 2021

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

Views

320

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 26, 2021 Jul 26, 2021

I shall repeat what I said:

  1. store the function as a variable in application scope, it will be available in all CFM pages of the application.
  2. test the example I gave you, and you will see it for yourself.

 

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
...

Votes

Translate

Translate
Community Expert ,
Jul 24, 2021 Jul 24, 2021

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!

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 26, 2021 Jul 26, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

quote

 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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Jul 26, 2021 Jul 26, 2021

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 26, 2021 Jul 26, 2021

Copy link to clipboard

Copied

I shall repeat what I said:

  1. store the function as a variable in application scope, it will be available in all CFM pages of the application.
  2. test the example I gave you, and you will see it for yourself.

 

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>

 

 

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 28, 2021 Jul 28, 2021

Copy link to clipboard

Copied

LATEST

Does that solve your problem? If you have further questions, don't hesitate to ask.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation