- ColdFusion 9 Developer Tutorial
- John Farrar
- 389字
- 2021-08-05 16:16:39
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.
- 中文版CorelDRAW X7基礎(chǔ)培訓(xùn)教程(移動學(xué)習(xí)版)
- 3ds Max & Unreal Engine 4:VR三維建模技術(shù)實(shí)例教程(附VR模型)
- Photoshop+Adobe Camera Raw+Lightroom(攝影后期照片潤飾實(shí)戰(zhàn))
- 中文版Photoshop CS6全能一本通·全彩版
- Android User Interface Development: Beginner's Guide
- 新編AutoCAD制圖快捷命令速查一冊通
- Java EE 6 with GlassFish 3 Application Server
- Photoshop CS6完美創(chuàng)意設(shè)計(jì):不一樣的圖像藝術(shù)處理
- Learning the Yahoo! User Interface library
- Microsoft SQL Azure Enterprise Application Development
- 巧用ChatGPT高效搞定Excel數(shù)據(jù)分析
- Photoshop+Illustrator+CorelDRAW一站式高效學(xué)習(xí)一本通
- Oracle BI Publisher 11g: A Practical Guide to Enterprise Reporting
- 手把手教你學(xué)成Excel高手
- 剪映專業(yè)版:PC端短視頻制作(全彩慕課版)