Upload
ella-sherman
View
223
Download
3
Tags:
Embed Size (px)
Citation preview
CFUNITED – The premier ColdFusion conference www.cfunited.com
ColdFusion ColdFusion ComponentsComponents
Ajay [email protected]
http://www.teratech.com
Based on presentation at the CFUNITED 06 Conference by Ray Camden
June 28th – July 1st 2006
About MeAbout Me
Certified ColdFusion MX Developer Microsoft Certified Solution Developer ColdFusion Developer 7+ years with ColdFusion Also work with SQL, JavaScript, HTML,
Access, VB, Oracle On site and custom development Fusebox and Process Methodology
June 28th – July 1st 2006
Why .Net developers envy us…Why .Net developers envy us…
June 28th – July 1st 2006
ColdFusion ComponentsColdFusion Components
What are they?A component can be thought of a
combination of data (properties) and functions (methods)
A simple mechanism for building web services
It is not object orientation!
June 28th – July 1st 2006
BasicsBasics
Must be named with cfc extension Collection of user-defined functions
wrapped with <cfcomponent> tags In general, basic CFML Very simple!
June 28th – July 1st 2006
This simple…This simple…
June 28th – July 1st 2006
<cfcomponent><cfcomponent>
displayName hint output extends More arguments for web services
June 28th – July 1st 2006
<cffunction><cffunction>
name returnType roles access output displayName, hint, description
June 28th – July 1st 2006
ColdFusion ComponentsColdFusion Components
Example
June 28th – July 1st 2006
Using ComponentsUsing Components
<cfinvoke> createObject() Direct invocation via Form, URL, Flash
Remoting Web Services
June 28th – July 1st 2006
<cfinvoke> & <cfinvokeargument><cfinvoke> & <cfinvokeargument>
component (name or variable) method returnVariable argumentCollection cfinvokeargument: name/value/omit
June 28th – July 1st 2006
<cfinvoke> & <cfinvokeargument><cfinvoke> & <cfinvokeargument>
Example
June 28th – July 1st 2006
createObject() & cfobjectcreateObject() & cfobject
Allows you to create an “instance” of the CFC.
<cfset theCFC = createObject(“component”, “myCFC”)>
June 28th – July 1st 2006
createObject() & cfobjectcreateObject() & cfobject
Example
June 28th – July 1st 2006
Direct InvocationDirect Invocation
URL Form
June 28th – July 1st 2006
CFCs with DataCFCs with Data
Two Scopes (This/Variables)Variables is an internal scope.This is an external scope.
Can persist between calls (if the CFC persists)
June 28th – July 1st 2006
CFCs with DataCFCs with Data
Example
June 28th – July 1st 2006
This versus VariablesThis versus Variables
Because the This scope is available outside the component, many developers shy away from it since it can lead to a lack of encapsulation.
Just (don’t) do it!Remember the 99% rule!
June 28th – July 1st 2006
CFC InitializersCFC Initializers
All code outside of cffunction tags is run automatically
Use an init() method
June 28th – July 1st 2006
CFC InitializersCFC Initializers
Example
June 28th – July 1st 2006
CFC SecurityCFC Security
AccessDefines how the methods can be called.Roles:
Private Public Remote Package
RolesDefines who can call the methods.
June 28th – July 1st 2006
CFC SecurityCFC Security
Example
June 28th – July 1st 2006
MetadataMetadata
getMetaData() Returns a whole heck of a lot of stuff! Used by the descriptor
June 28th – July 1st 2006
MetadataMetadata
Example
June 28th – July 1st 2006
““Best” PracticesBest” Practices
June 28th – July 1st 2006
Var ScopeVar Scope
Or die the death of a thousand cuts… Any variable created inside a method
must be properly scoped. Note new “result” attributes in CFMX7
June 28th – July 1st 2006
Don’t use “outsiders”Don’t use “outsiders”
CFCs should never* use:ApplicationSessionClientURL, Form, CGI, Server, Etc
But the opposite is not true…
* Except when I say it’s ok.
June 28th – July 1st 2006
Strip that output…Strip that output…
output=“false” Applies to both cfcomponent and
cffunction
June 28th – July 1st 2006
Strip that output…Strip that output…
Example
June 28th – July 1st 2006
Got cache?Got cache?
Creating a CFC is expensive. Only make em when ya need em! Data inside can be cached as well.
June 28th – July 1st 2006
Have FunHave Fun