We are going to look into using the ColdFusion components known as CFC’s and how easy they can make your web applications.

Some benefits of using CFCs

  • Better security
  • Reuseable code
  • Faster applications

The tutorial
Our first step is to create a database & datasource, you can find all SQL & source files with the ZIP file attached to this thread (You may need to login to access).

users.cfc

Code:
<cfcomponent displayname="Users" hint="The main display name for the component">

	<cffunction name="getUsers" hint="Gets users function" access="public" returntype="query">

		<cfquery name="allUsers" datasource="yours_datasource">
			SELECT *
			FROM users
		</cfquery>

		<cfreturn allUsers>

	</cffunction>

</cfcomponent>

Our first bit of code is the main component as you can see we have ‘cfcomponent’ to start with the define the component. The next tag is the function which in this case is a query as we want to select everything from a database.

Next is the query, its just a normal query as you would do in ColdFusion. We then add a return so we can return the information from the database. Then we just close the tags.

index.cfm

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Using CFCs</title>
</head>

<body>

<cfinvoke component="users" method="getUsers" returnvariable="listUsers"></cfinvoke>

<p>Get Users:</p>

<ul>
<cfoutput query="listUsers">
	<li>#id#</li>
</cfoutput>
</ul>

</body>
</html>

The main area of this code you are probable looking at is the ‘cfinvoke’ tag, this calls the component. You may be asking why cant I just use a .cfm file for the query and do an include, well you could but an cfinclude will not be compiled by coldfusion and will run a lot slower where a CFC will be faster.

After the cfinvoke we can just do a cfoutput with the query as shown above.

Well thats it for CFC’s, working with them is better practice and also better when working in a team so you can start to extend each others components.

Join the conversation! 82 Comments

  1. tadalafil 10mg without prescription – order cialis 5mg online cheap cialis tadalafil 20mg

    Reply
  2. order hydroxychloroquine 200mg generic – buy generic hydroxychloroquine hydroxychloroquine 200mg ca

    Reply
  3. ivermectin for humans walmart – ivermectin medicine ivermectin 3mg for people

    Reply
  4. order cephalexin – cleocin drug erythromycin usa

    Reply
  5. buy fildena 50mg sale – cheap fildena 50mg order antabuse for sale

    Reply
  6. purchase rhinocort for sale – cefuroxime 500mg price cefuroxime 250mg ca

    Reply
  7. sildenafil brand – brand sildenafil 100mg order zantac 300mg sale

    Reply
  8. cialis order – tadalafil pill ivermectin 6mg without a doctor prescription

    Reply
  9. cheap cialis generic – hims ed pills buy ed pills gb

    Reply
  10. slot games online – best real money casino generic prednisone 5mg

    Reply
  11. prednisone 40mg cost – accutane for sale cheap isotretinoin 40mg

    Reply
  12. amoxil price – buy amoxil 500mg for sale order viagra 100mg sale

    Reply
  13. cialis walmart – cialis order tadalafil 10mg cost

    Reply
  14. buy stromectol europe – buy stromectol online cheap azithromycin 500mg

    Reply
  15. order azithromycin 250mg online – methylprednisolone 8mg otc methylprednisolone without prescription

    Reply
  16. order baricitinib 2mg without prescription – chloroquine for sale buy priligy 60mg sale

    Reply
  17. order generic metformin 500mg – legal canadian prescription drugs online lipitor generic

    Reply
  18. norvasc 5mg sale – omeprazole 10mg oral buy omeprazole 10mg without prescription

    Reply
  19. buy lopressor 100mg without prescription – order generic lopressor order cialis 5mg online cheap

    Reply
  20. buy generic cialis 5mg – sildenafil fast shipping oral viagra 50mg

    Reply
  21. Thanks so much for the article.Much thanks again.

    Reply
  22. ivermectin pills – ivermectin 12mg online ivermectin 5

    Reply
  23. clomid pill – buy clomiphene pill buy zyrtec 10mg pill

    Reply
  24. buy generic clarinex – order aristocort 4mg pill buy aristocort online

    Reply
  25. order misoprostol generic – purchase cytotec for sale order synthroid 100mcg online cheap

    Reply
  26. viagra 50mg for sale – viagra pills 200mg order gabapentin sale

    Reply
  27. cheap tadalafil pill – cenforce 100mg pill order cenforce

    Reply
  28. order diltiazem online cheap – zovirax tablet acyclovir cost

    Reply
  29. atarax order – hydroxyzine sale crestor 10mg generic

    Reply
  30. buy ezetimibe pill – celexa 20mg uk citalopram order

    Reply
  31. viagra 150mg canada – sildenafil 100 mg buy flexeril pill

    Reply
  32. Hello, I think your blog might be having browser compatibility issues.
    When I look at your website in Ie, it looks fine but when opening in Internet Explorer,
    it has some overlapping. I just wanted to give you a quick heads up!
    Other then that, awesome blog!

    Reply
  33. viagra over the counter – order cialis 10mg for sale cialis sales

    Reply
  34. oral toradol 10mg – tizanidine 2mg pill lioresal uk

    Reply
  35. Thanks for finally talking about > [Tutorial] ColdFusion Components | Host
    Media < Loved it!

    Reply
  36. Right away I am going to do my breakfast, after having my breakfast coming again to read other news.

    Reply
  37. colchicine cheap – buy inderal 10mg pill oral strattera 10mg

    Reply
  38. order viagra 100mg pill – purchase sildenafil generic plavix 75mg brand

    Reply
  39. 50mg viagra – sildenafil 50mg cost buy plavix 150mg generic

    Reply
  40. guaranteed viagra overnight delivery usa – sildenafil 100mg price viagra 150mg cheap

    Reply
  41. order nexium 40mg – order nexium 20mg online buy phenergan

    Reply
  42. tadalafil 5mg sale – Buy generic cialis best cialis sites online

    Reply
  43. order provigil generic – erection pills that work cheapest ed pills

    Reply
  44. What’s up everyone, it’s my first go to see at this web
    page, and post is truly fruitful in support of me, keep up posting these content.

    Reply
  45. We stumbled over here by a different page and thought I should check things out.
    I like what I see so i am just following you. Look forward to exploring
    your web page yet again.

    Reply
  46. isotretinoin 40mg brand – order azithromycin pill order azithromycin 500mg pills

    Reply
  47. Howdy! I’m at work browsing your blog from my new iphone 4!
    Just wanted to say I love reading through your blog and
    look forward to all your posts! Carry on the superb work!

    Reply
  48. Why viewers still use to read news papers when in this technological globe the whole thing is accessible on net?

    Reply
  49. furosemide drug – lasix generic order generic viagra 50mg

    Reply
  50. Hello there! I could have sworn I’ve visited this website before but after browsing through some of the articles I realized it’s new to me.
    Anyways, I’m definitely pleased I found it and I’ll be book-marking it and checking back frequently!

    Reply
  51. order cialis 5mg sale – cialis mail order usa female viagra pill

    Reply
  52. It’s perfect time to make some plans for the future and it’s time to be happy.
    I’ve read this post and if I could I wish to suggest you some
    interesting things or tips. Perhaps you can write
    next articles referring to this article. I desire to read more things about
    it!

    Reply
  53. What’s Taking place i’m new to this, I stumbled upon this I have found It absolutely helpful and it has aided me out loads.
    I am hoping to give a contribution & aid different users like its aided me.
    Great job.

    Reply
  54. My relatives every time say that I am wasting my
    time here at net, except I know I am getting familiarity every day by reading thes
    pleasant posts.

    Reply
  55. buy topiramate pills – generic topamax 100mg imitrex 25mg uk

    Reply
  56. buy avodart 0.5mg pills – avodart online coupon for cialis

    Reply
  57. This piece of writing is truly a pleasant one it helps
    new web viewers, who are wishing for blogging.

    Reply
  58. cheap sildenafil 50mg – order viagra 50mg pills order tadalafil generic

    Reply
  59. ed pills that work – buy prednisone 20mg prednisone 10mg ca

    Reply
  60. purchase accutane generic – generic accutane 20mg amoxicillin ca

    Reply
  61. lasix for sale online – buy furosemide 100mg pills generic azithromycin

    Reply
  62. order doxycycline 100mg for sale – order chloroquine pill chloroquine order online

    Reply
  63. tadalafil 20mg price – Buy now cialis sildenafil citrate

    Reply
  64. order provigil sale – viagra 100mg cost buy sildenafil 150mg

    Reply
  65. buying ed pills online – prednisone 40mg cost cheap deltasone 20mg

    Reply
  66. buy isotretinoin 10mg online – buy amoxicillin 500mg generic celecoxib 200mg sale

    Reply
  67. buy flomax 0.2mg generic – order tamsulosin 0.4mg sale spironolactone 25mg oral

    Reply
  68. online casinos real money – casino slots free essays help

    Reply
  69. casino slot games – propecia 1mg usa purchase ampicillin generic

    Reply
  70. purchase ciprofloxacin pills – cialis 10mg usa cheap tadalafil sale

    Reply
  71. order generic sildenafil 150mg – buy prednisone 20mg without prescription where can i buy vardenafil online

    Reply
  72. prednisolone 5mg pill – order gabapentin generic oral cialis 10mg

    Reply
  73. Excellent post. I used to be checking continuously this weblog and I’m inspired!
    Very useful info specially the last part 🙂 I care for such information much.

    I was seeking this particular information for a
    long time. Thank you and best of luck.

    Reply
  74. augmentin 625mg sale – buy augmentin 625mg online cialis pill

    Reply
  75. Wow, fantastic blog layout! How long have you been blogging for?

    you made blogging look easy. The overall look of your web site is wonderful,
    as well as the content!

    Reply
  76. sulfamethoxazole price – brand bactrim 480mg cost of viagra 100mg

    Reply
  77. cephalexin 250mg canada – buy cleocin 300mg online brand erythromycin 250mg

    Reply
  78. It’s not my first time to visit this site, i
    am browsing this website dailly and take pleasant data from here
    every day.

    Reply
  79. sildenafil 100mg sale – generic nolvadex 10mg ivermectin cream 5%

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

About Host Media

We have been hosting websites since 2002 and are always moving forward. All articles written under the Host Media author are created by the team who support our customers.

Category

ColdFusion/Railo & MySQL

Tags

, ,