Solved

Multiple CFC's Conflict

Posted on 2004-10-07
14
457 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
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

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…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

688 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