Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
CFCs are powerful, but they can sometimes be mighty boring to build. Developing services and writing value objects usually consists of a bunch of repetitive and potentially error-prone code. ColdFusion 9's ORM capabilities can help with all that, but we are not all on ColdFusion 9 yet, and some applications just aren't set up to support ORM-based objects. Luckily, ColdFusion Builder can take care of some of the grunt work with creating CFCs to connect to databases in our ColdFusion 8 based applications. So, in the last video, we installed the CFC Generator and here I am going to show you how to use it.
In the RDS Data view, I am going to expand my local server and the cfartgallery data source. I will expand the tables and I am going to create a batch of CFCs for my ARTISTS table. If I right-click on the table, at the bottom you can see Adobe CFC Generator, and we are going to select Create CFC. This opens up the Adobe CFC Generator dialog, which just has three options. The first is where I want my CFCs to go. The second is whether I want it to generate a Service CFC, along with the value objects. And the third is whether I want it to do a ColdFusion 9 CFScript-based CFC or if I want to stick with standard tags.
So, click Browse and we will choose exactly where we want our CFCs to go. I am going to put them directly in my Chapter 7 folder. Click OK. Click OK again. The CFBuilder is passing control off to the ColdFusion server. It's going to take a look at my table and then build all of these CFCs. I now have an ARTISTS CFC value object. I have a Data Access object, a Gateway object, and a Service. I am going to go ahead and open up the Service and we will take a quick look at everything that the extension did for us.
If I switch to the Outline view and scroll down the list here, I can see it has created a count function, createARTISTS, deleteARTISTS, getARTISTS, getARTISTS_page, where I can actually pass in my startIndex and the number of items I want it to return. It has generated a lot of code inside just this one CFC. I have got 117 lines of ColdFusion that I didn't have to write. If I open up the Gateway, I can see I have getALL, getALL_page.
I have the same type of methods that my Service had. So, let's go ahead and make sure that these actually work. If I open up my index.cfm, let's output the result of one of these CFCs. Let's dump the getALL method from our Gateway. So, I will run CreateObject ("component", ArtistsGateway").getALL method. I will save my file, switch to the browser preview, and here we can see that the getALL method returned us an array of individual artist objects.
That's all it took to generate all that code. Just a single right-click and clicking Finish. So, because that was so quick, I am going to take a little bit of time and show you how you can adjust this code if you don't like the way that it's being generated. So, for example, in the ARTISTSGateway, maybe I don't like the way it's running the set methods or maybe I want an additional method added to the CFC. If you go to the Adobe CFC Generator folder, go to the handlers directory > com > adobe > cfbuilder, you will see there's a templates directory.
If I expand the templates directory, I can see I have templates for the standard crud methods, which we just used, and the ORM CFCs, which I will show you in the next video. If I expand the crud folder, I will scroll over a little bit here. We can see cfm files for generating the dao, the gateway, a script-based DAO, the script-based Gateway, and then my value objects. So, if I open up the gateway.cfm file -- and I will scroll down a little bit here -- you can see a whole bunch of code that determines how the init method is formatted, how the getALL method is formatted.
You can see some fancy stuff around looping over table names and columns, and you can take this file, change it however you please, save it, and rerun the extension. It will generate the code just as you would like it to be generated. So, if we wanted to change the name of the getALL method, I can change that to say getALLObjects. I will save this CFM file, go back to my RDS view, and let's create some CFCs for the Media table. I will Run Create CFC, choose my destination.
We are going to stick this in the same Chapter 7 folder, click OK, OK again. If I scroll over here, go back down to our Chapter 7 folder, and here I can see my MEDIAGateway. I will open that up, and now my getALL method is get ALLObjects. So, my suggestion to you would be to run the CFC Generator, go through the code, find out what you don't like. For example, single quotes instead of double quotes. Change what you would like to be different, save the files, and now the extension will work exactly the way you would like it to.
Get unlimited access to all courses for just $25/month.Become a member
82 Video lessons · 97479 Viewers
61 Video lessons · 84712 Viewers
71 Video lessons · 68907 Viewers
56 Video lessons · 101355 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.
Your file was successfully uploaded.