Coldfusion Component cfc Compile

When i change a cfc and then test it it appears to hang the page the first time.  I have cf11.  Do I have to compile first? How do I do that? Also I can only get it to work if I place in root directory  / . I have test environments. /test4  How would I invoke from there?

<cfparam name="variables.VariableNumberOfNotifications" type="numeric" default="0">
<cfparam name="variables.NotificationsMemberId" type="numeric" default="0">
<cfinvoke component="CountNotifications_3"
          method="CountNotifications"
          SubtractDays="2" NotificationsMemberId = "#session.memberId#"
          returnVariable="NotificationsCount" />
<cfset Variables.NumberOfNotifications =   NotificationsCount>

Open in new window

Ian WhiteOwner and FounderAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgrafxCommented:
No - you don't need to compile first. Just write the code - run it - CF compiles by itself

When you say you have test environments - are these setup as websites in iis or whatever web server?
If yes then I believe the easiest would be a mapping.
But if not - meaning you have just the one website and you navigate your browser to /test4 then simply calling the component will work.
It is best practice to create a location for all cfc files just like an images directory that houses all your images.
So create a directory in your root named cfcs (or whatever).
Then refer to a component that is in that cfcs dir like this: cfcs.mycomponent - note that in the examples below I use "cfcs" which will be a dir in your web root.

A few comments
First off you are setting default variables (cfparam) and are not using them.
1. variables.VariableNumberOfNotifications - I believe you mean to set a default for variables.NumberOfNotifications instead.
2. variables.NotificationsMemberId - this I believe is a misconception. You aren't using NotificationsMemberId as a variable name but are sending in an argument named NotificationsMemberId to the component whose value is session.memberId - do you see what I mean?

Secondly you should actually be coding like this:
To set the proper path you would code it in the component setting - see below.
<cfinvoke component="cfcs.CountNotifications_3" method="CountNotifications" returnVariable="NotificationsCount">
      <cfinvokeargument name="SubtractDays" value="2"/>
      <cfinvokeargument name="NotificationsMemberId" value="#session.memberId#"/>
</cfinvoke>
And if NumberOfNotifications is the same as NotificationsCount then why not just use NotificationsCount? Or set the returnVariable to NumberOfNotifications?
Plus it doesn't look like any need for default params for this chunk of code.

Thirdly - a better way would be:
<cfset Notifications = New cfcs.CountNotifications_3() /> Note that I would typically init a datasource here as well but don't know what your situation is.
Now look at this variable named Notifications
<cfdump var="#variables.Notifications#">
You should see whatever functions are in the CountNotifications_3.cfc
If you just have the one then that's all you'll see

Now call your function:
      <cfset NotificationsCount = Notifications.CountNotifications(
                                                SubtractDays=2,
                                                NotificationsMemberId=session.memberId
                                                )
      />
the variable NotificationsCount is your value

And also note that your variable Notifications is persistent throughout your page - meaning that if you have several functions in your CountNotifications_3.cfc file and you want to call a second function you can just do it without needing to call the component first then the function like you do with cfinvoke.
Or even calling the same function sending in different values then this is the way to go especially when calling data from a database as the DB in only hit once when the object is created.
See below:
Here is an example output loop that outputs your members
<cfloop query="mymembers">
      <cfset NotificationsCount = Notifications.CountNotifications(
                                                SubtractDays=2,
                                                NotificationsMemberId=mymembers.memberID
                                                )
      />
      #mymembers.membername# (#mymembers.memberID#) : #variables.NotificationsCount#<br />
</cfloop>
The most important thing is that you are querying the object Notifications and not touching the DB again after creating it
This is one of the key values of persistence

good luck ...

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ian WhiteOwner and FounderAuthor Commented:
Thank you for your clear explanation, very helpfull
dgrafxCommented:
glad it helped !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ColdFusion Language

From novice to tech pro — start learning today.