Solved

Multiple CFC's Conflict

Posted on 2004-10-07
14
456 Views
Last Modified: 2013-12-24
New to CFC's and trying to get both CFC's to coexist on the same .cfc document.  Here are my cfc's:

<!--- LIST AFFILIATES --->
<cfcomponent>
  <cffunction name="listAffiliates" access="public" returntype="query">
    <cfargument name="catID" type="numeric" required="yes">
    <cfif isDefined("URL.catID") and NOT isNumeric(URL.catID)>
      <cflocation url="index.cfm" addtoken="no">
    </cfif>
    <cfquery datasource="AdminTool" name="getAffiliates">
    select c.category_name, c.categoryID, a.affiliate_name, a.affiliate_logo,
    a.affiliate_blurb, a.affiliate_url from SLP_1179_AFFILIATES_CATEGORIES_TBL
    c inner join SLP_1179_AFFILIATES_CATEGORIES_AFFILIATES_TBL ca on c.categoryID
    = ca.categoryID inner join SLP_1179_AFFILIATES_TBL a on ca.affiliateID =
    a.affiliateID where
    <cfif isDefined("ARGUMENTS.catID")>
      c.categoryID =
      <cfqueryparam cfsqltype="cf_sql_integer" value="#ARGUMENTS.catID#">
      and
    </cfif>
    c.category_on = 1 and a.affiliate_on = 1 order by c.category_rank, c.category_name,
    a.affiliate_rank, a.affiliate_name
    </cfquery>
    <cfreturn getAffiliates>
  </cffunction>
</cfcomponent>
<!--- LIST NEWS --->
<cfcomponent>
  <cffunction name="listNews" access="public" returntype="query">
    <cfquery name="getNews" datasource="AdminTool">
    select n.news_ID, n.news_title, n.news_timestamp, n.news_blurb, n.news_feature
    as feature, n.news_article, n.news_upload, f.file_name, news_url = '' from
    SLP_1024_NEWS_TBL n left outer join (select nf.news_ID, u.file_name from
    SLP_1024_NEWS_FILES_TBL nf inner join SLP_1024_UPLOADS_TBL u on nf.fileID
    = u.fileID where file_type = 2) as f on n.news_ID = f.news_ID where news_orlive_on
    = 1 and news_on = 1
    </cfquery>
    <cfreturn getNews>
  </cffunction>
</cfcomponent>

I invoke CFC's on seperate web pages:

<!--- INVOKE CFC --->
<cfinvoke component="orQuery" method="listAffiliates" catID="#URL.catID#" returnvariable="getAffiliates">
<cfinvoke component="orQuery" method="listNews" returnvariable="getNews">


I have tried each seperately and they work great.  However, when combined on the same .cfc document, they do not work.  Is the syntax incorrect?  Is it possible?  Also, can an alias be used for cfquery  datasource="#myDSN# as opposed to  datasource="AdminTool"?  Coldfusion would say myDSN is undefined.

Thanks,

Terry


0
Comment
Question by:splendorx
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
  • +2
14 Comments
 
LVL 9

Expert Comment

by:CFDevHead
ID: 12253214
try just useing one cfcomponent tags that should take care of the error
0
 
LVL 9

Expert Comment

by:CFDevHead
ID: 12253223
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 125 total points
ID: 12253255
You cannot have two cfc's in the same document.

One cfcomponent tag per document

The cfc is named by the document name

You could have multiple functions within the same cfc....
0
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
LVL 9

Expert Comment

by:CFDevHead
ID: 12253284
thats correct.
0
 
LVL 1

Author Comment

by:splendorx
ID: 12253741
It works great!  However, why does it not work with:

<cfquery name="getNews" datasource="#myDSN#">

and it works with:

<cfquery name="getNews" datasource="AdminTool">

A regular query within a .cfm web page works fine with #myDSN#.  Any ideas?
0
 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 125 total points
ID: 12253790
if myDSN is declared in your application page or a config cfm page  a cfc can't see variables out side of the cfc except session request and some others
0
 
LVL 35

Expert Comment

by:mrichmon
ID: 12254261
correct
0
 
LVL 17

Expert Comment

by:Tacobell777
ID: 12255425
if you want to use the functionality of another CFC, then use composition, i.e. something like

<cfcomponent>

function name="init" ....
<cfset this.myComposition = createObject("component", "myCFCToAdd") />

rest of the function here

</cfcomponent>

You can then call this.myComposition.method()
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12301954
When you create the object, you can wrap cfif tags around it like this:

<cfif NOT IsObject("myComponent")>
Component set
</cfif>

This way, if the object is already set in ColdFusion, the code won't run again and kick out an error.
0
 
LVL 7

Expert Comment

by:black0ps
ID: 12301977
Might also want to try using #Caller.MyDSN# instead of just #MyDSN#
0
 
LVL 1

Author Comment

by:splendorx
ID: 12351526
tried using #CALLER.g_DSN#, but threw an error.

Element G_DSN is undefined in CALLER.

0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
One of the typical problems I have experienced is when you have to move a web server from one hosting site to another. You normally prepare all on the new host, transfer the site, change DNS and cross your fingers hoping all will be ok on new server…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question