Solved

Multiple CFC's Conflict

Posted on 2004-10-07
14
453 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
  • 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
 
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

867 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now