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

cfcomponent extends question

Advisor ,
Apr 05, 2013 Apr 05, 2013

Copy link to clipboard

Copied

Hi all,

i have two cfc' components usind extends as:

<!--- myParent.cfc --->

<cfcomponent displayname="myParent" output="false">

    <cfscript>

         this.myData = '';

    </cfscript>

    <cffunction access="remote" name="setQueryData" output="false" >

         <cfquery name="this.myData" datasource="#myDatasource#">

            SELECT *

            FROM myTable

        </cfquery>

    </cffunction>

</cfcomponent>

<!--- myExtend.cfc --->

<cfcomponent extends="myParent">

     <cffunction access="remote" name="getData" output="false" >

         <cfquery name="qryData" datasource="#myDatasource#">

            SELECT *

            FROM this.myData

        </cfquery>

     <cfreturn qryData />

    </cffunction>

</cfcomponent>

<!--- myTest.cfm --->

<cfset myObj = CreateObject("component", "cfcs.myParent") />

<cfset myObj.setQueryData() />

<cfset mySecondObj = CreateObject("component", "cfcs.myChild") />

<cfset finalData = mySecondObj.getData() />

<cfdump var="#finalData#">

this.myData is available in the child cfc component but it doesn't show any data.

Can I access data between components?

Thanks

Views

1.1K

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

Advisor , Apr 08, 2013 Apr 08, 2013

I got it Dan,

In my parent component i need to declate the extend name as:

<cfcomponent displayname="myParent" output="false" extends="myExtend" >

Now I can access to all with:

<cfset finalData = myObj.getData() />

Also I am using variables instead of this. Thiscan be use to make a call outside the scope.

Best,

Votes

Translate

Translate
LEGEND ,
Apr 06, 2013 Apr 06, 2013

Copy link to clipboard

Copied

I'm surprised you didn't get an error running that code.  It looks like you are trying to do a query of queries, but you have a datasource attribute in your query tag.

As far as your question goes, your myObj and mySecondObj objects are independent.  To do what you are attempting, you have to run the setQueryData function from the child component.

Your scopes might also be incorrect.  I never do this sort of thing in ColdFusion so I can't be sure.  In other programming languages, you use the word base, or parent in the child classes.  I could look up the correct scope for ColdFusion, but so could you.

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
Advisor ,
Apr 08, 2013 Apr 08, 2013

Copy link to clipboard

Copied

Hi Dan,

I try to create a sample code from original code, i didn't test the code but i will.

The issue is that my cfc file is huge and my flex text editor is crashing, so i want to keep going with a new cfc file, i dont want to call the data again becuase affect my page performance.

How can I extend my cfc file and use the same data?

Thanks for you reply and help!

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
LEGEND ,
Apr 08, 2013 Apr 08, 2013

Copy link to clipboard

Copied

Caching your query might be appropriate for this situation.

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
Advisor ,
Apr 08, 2013 Apr 08, 2013

Copy link to clipboard

Copied

LATEST

I got it Dan,

In my parent component i need to declate the extend name as:

<cfcomponent displayname="myParent" output="false" extends="myExtend" >

Now I can access to all with:

<cfset finalData = myObj.getData() />

Also I am using variables instead of this. Thiscan be use to make a call outside the scope.

Best,

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