0

I am creating a CFC called "core_appdata". This CFC will hold the core stored procedures for an application. Example....

    <cfcomponent displayname="core_appdata" hint="I Return Core App Data" output="no">
    <cffunction name="getprogram_list">

  <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
   <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
    <cfargument name="getstoredproc_input_startdate" type="date" required="false">
    <cfargument name="getstoredproc_input_enddate" type="date" required="false">
    <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
    <cfargument name="getstoredproc_input_listid" type="string" required="false">
    <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

    <cfset var rst_getprogram_list ="">
     ---  stored proc ---            
         <cfstoredproc procedure  = "p_adb_getprogram_list">
         </cfstoredproc>

    <cfreturn rst_getprogram_list />
   </cffunction>
    </cfcomponent> 

I would also like to create a CFC called "core_appdata_grids". This CFC would be used to bind to cfgrids and allow paging etc. In a perfect world, this CFC would get its data from the method/function "getprogram_list" in the CFC "core_appdata" above. Example...

    <cfcomponent displayname="core_appdata_grids" hint="I Return Core App Data For CFGrids " output="no">

    <cffunction name="getprogram_list_grid">

               <cfargument name="page" required="no" />
        <cfargument name="pageSize" required="no" />
        <cfargument name="gridsortcolumn" required="no" />
        <cfargument name="gridsortdirection" required="no" />   
        <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
               <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
               <cfargument name="getstoredproc_input_startdate" type="date" required="false">
               <cfargument name="getstoredproc_input_enddate" type="date" required="false">
               <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
               <cfargument name="getstoredproc_input_listid" type="string" required="false">
                <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

        <cfset var rst_getprogram_list_grid ="">
         ---  get data ---           


        <cfreturn queryconvertforgrid(rst_getprogram_list_grid, page, pagesize) />
    </cffunction>

     </cfcomponent>

Questions:

  • Is this possible? If so, how is it done?
  • If so, is this best practice when working with CFCs?
  • If not, what is the best way to share data between CFCs

Thank you in advance for your time in helping me with this question.

OC

  • Yes it is possible, and there are many ways to do it. I am not sure there is a best way. There are many ways to get variables in one area to be visible in another. A better question might be, what are the facilities to share data between CFCs – James A Mohler Nov 28 '12 at 18:59

2 Answers2

2

I can't see the name of the cfc that produces the grid but just extend the base cfc which will inherit all the methods.

<cfcomponent extends="core_appdata">

<cffunction name="getprogram_list_grid">
    <cfargument name="page" required="no" />
    <cfargument name="pageSize" required="no" />
    <cfargument name="gridsortcolumn" required="no" />
    <cfargument name="gridsortdirection" required="no" />   
    <cfargument name="getstoredproc_input_campaignid" type="string" required="false">
    <cfargument name="getstoredproc_input_filtertestrecs" type="string" required="false">
    <cfargument name="getstoredproc_input_startdate" type="date" required="false">
    <cfargument name="getstoredproc_input_enddate" type="date" required="false">
    <cfargument name="getstoredproc_input_listtypeid" type="string" required="false">
    <cfargument name="getstoredproc_input_listid" type="string" required="false">
    <cfargument name="getstoredproc_input_appenvr" type="string" required="false">

    <cfset var rst_getprogram_list_grid = super.getprogram_list() />

    <cfreturn queryconvertforgrid(rst_getprogram_list_grid, page, pagesize) />
</cffunction>

</cfcomponent>
Paul
  • 1,547
  • 7
  • 10
  • I have updated my code up above to show the missing CFC names/function names. I think I understand your instruction, I just need clarification on setting the output variable in the extended CFC: `` thanks for your help... OC – Oliver Codewell Aug 22 '12 at 00:38
  • super.theMethodNameThatRunsTheStoredProd is the method name of the first code block you provided. I altered my code to reflect your method names. – Paul Aug 22 '12 at 01:21
  • Nice Paul - elegant. Let me know if you ever want a change of scenery :) – Mark A Kruger Aug 22 '12 at 13:10
1

If you don't want to extend the CFC, especially if that's not being true to your model, you could just call the other CFC:

<cfset var rst_getprogram_list_grid = createObject("component","core_appdata").getprogram_list() />

OR even better somewhere above it all set:

<cfset request.core_appdata=createObject("component","core_appdata")>

And then in your CFC:

<cfset var rst_getprogram_list_grid = request.core_appdata.getprogram_list() />

Just a few options.

Nicklepedde
  • 466
  • 2
  • 10