?
Solved

Multiple CFC's Conflict

Posted on 2004-10-07
14
Medium Priority
?
458 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 500 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
Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

 
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 500 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

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
What You Need to Know when Searching for a Webhost Provider
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

771 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