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

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.

主站蜘蛛池模板: 多伦县| 巨野县| 宣城市| 大同市| 通河县| 翼城县| 南京市| 太仆寺旗| 东城区| 赫章县| 洛阳市| 平江县| 迁安市| 罗甸县| 巢湖市| 临朐县| 六安市| 汉源县| 永吉县| 桂东县| 安国市| 巢湖市| 宜章县| 揭西县| 襄汾县| 海盐县| 开远市| 博客| 安丘市| 冕宁县| 辽宁省| 澄城县| 泾源县| 石家庄市| 滁州市| 韶山市| 湖南省| 绵竹市| 阳江市| 南部县| 明光市|