Solved

Multiple CFC's Conflict

Posted on 2004-10-07
14
451 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
Comment Utility
try just useing one cfcomponent tags that should take care of the error
0
 
LVL 9

Expert Comment

by:CFDevHead
Comment Utility
0
 
LVL 35

Accepted Solution

by:
mrichmon earned 125 total points
Comment Utility
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
Comment Utility
thats correct.
0
 
LVL 1

Author Comment

by:splendorx
Comment Utility
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 9

Assisted Solution

by:CFDevHead
CFDevHead earned 125 total points
Comment Utility
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
Comment Utility
correct
0
 
LVL 17

Expert Comment

by:Tacobell777
Comment Utility
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
Comment Utility
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
Comment Utility
Might also want to try using #Caller.MyDSN# instead of just #MyDSN#
0
 
LVL 1

Author Comment

by:splendorx
Comment Utility
tried using #CALLER.g_DSN#, but threw an error.

Element G_DSN is undefined in CALLER.

0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

772 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

15 Experts available now in Live!

Get 1:1 Help Now