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

The practice of protecting access

In CFC methods, there is an attribute called "access". The access methods are explained in

<cffunction name="setDefaults" access="private" output="false">
<cfset var iAttr = 0>
<cfloop list="#listLen(variables.field.names)#" index="iAttr">
<cfscript>
variables.attribute[#listGetAt(variables.field.names,iAttr)#] = setDefault(variables.field.names,iAttr);
</cfscript>
</cfloop>
</cffunction>

The logic for this would actually be used in more than one place inside the object. When the object is created during the first run, it would call the setDefaults() method and set the defaults. When you use the load method to insert another record inside the CFC, it will run this method. This will become simpler as you use CFCs and methods more often. This is a concept called refactoring, where we take common features and wrap them for reuse. This takes place even inside a CFC. Again, the setDefaults() function is just another method inside the same CFC.

Now, we look at the access attribute in the code example and note that it is set to private. This means that only this object can call the method. One of the benefits to CFCs is making code simpler. The interface to the outside world of the CFC is its methods. We can hide a method from the outside world, and also protect access to the method by setting the access attribute to private. If you want to make sure that only CFCs in the same directory can access these CFC's methods, then you will have to set the attribute to package. This is a value that is rarely used.

The default value for the access attribute is public. This means that any code running on the web server can access the CFC. (Shared hosting companies block one account from being able to see the other accounts on the same server. If you are concerned about your hosting company, then you should either ask them about this issue or move to a dedicated or virtual hosting server.)

The last value for the access attribute is remote. This is actually how you create a number of "cool power" uses of the CFC. There is a technology on the Web called web services. Setting the CFC to remote allows access to the CFC as a web service. You can also connect to this CFC through Flash applications, Flex, or AIR, using the remote access value. This method also allows the CFC to respond to AJAX calls. Now, we will learn to use more of the local power features.

主站蜘蛛池模板: 长海县| 香港| 潮州市| 鲁山县| 林口县| 永登县| 邓州市| 唐海县| 东明县| 深水埗区| 仁化县| 濉溪县| 绥芬河市| 云南省| 涿州市| 慈溪市| 龙川县| 锡林浩特市| 湘阴县| 汉中市| 孝义市| 梅河口市| 垫江县| 宁蒗| 平谷区| 财经| 双辽市| 兴城市| 丹凤县| 左贡县| 聂拉木县| 平谷区| 岢岚县| 元江| 汉源县| 仙桃市| 广饶县| 长汀县| 易门县| 北流市| 凌源市|