官术网_书友最值得收藏!

Our first CFC

We start by creating a file that ends with .cfc when creating CFCs. Non-CFC files that you have been creating up to this point, and will also continue to create, end with .cfm.

Each CFC is wrapped by a set of tags and has one or more functions, which are also referred to as methods. We will be creating an object class. There are different types of objects, and a CFC is the type we normally use in ColdFusion. Now, let us look at some empty code, so you can get an idea of what one might look like:

<cfcomponent>
<cffunction>
</cffunction>
</cfcomponent>>

Certainly, we cannot do much with this segment of code. This is just for us to get a first glimpse of CFC code. Here, we get an idea of what it is and start our journey of discovery. You see there is a<cfcomponent> tag that surrounds the whole CFC. You can add additional attributes, but for now we are going to keep it as simple as possible and try to learn how to write CFCs without getting bogged down with details. You can also see that we have included a function (<cffunction>) inside the CFC. This is also called a method. You will get used to them being referenced both ways.

Let's start by understanding the personality of our first object. At first, you are likely to wonder why we would call it a personality. This is because most of your objects can be thought of as a computer model of a real-world object. That will also help us with the concept of understanding what objects are and what they do.

Note

The code in this chapter is set up to work on the MySQL database resource. There is a script in the code bundle of Chapter 2 called cfb.sql that will create the tables needed to make the code work. If this is new to you, you can visit our site at http://books.sosensible.com/. We have tutorials on how to do this for this platform.

主站蜘蛛池模板: 大连市| 安乡县| 县级市| 成武县| 札达县| 雷州市| 吉首市| 东平县| 个旧市| 长海县| 类乌齐县| 砚山县| 大渡口区| 米脂县| 宜兴市| 秦安县| 黑龙江省| 巴塘县| 盐源县| 班戈县| 安平县| 彰武县| 枣阳市| 夹江县| 鹤峰县| 营口市| 阿瓦提县| 班戈县| 东兰县| 湖州市| 西乌珠穆沁旗| 高安市| 泾川县| 阳泉市| 诸暨市| 青岛市| 保康县| 信宜市| 宜州市| 托里县| 安顺市|