140 likes | 324 Views
N-tier ColdFusion Development with CFC’s. Neil Ross, MCP neil@codesweeper.com www.codesweeper.com www.insidecoldfusionmx.com. Introduction. Neil Ross Co-Author of Inside ColdFusion MX Certified ColdFusion Developer Certified ColdFusion Instructor Presenter at DevCon 2000 in DC
E N D
N-tier ColdFusion Development with CFC’s Neil Ross, MCP neil@codesweeper.com www.codesweeper.com www.insidecoldfusionmx.com
Introduction • Neil Ross • Co-Author of Inside ColdFusion MX • Certified ColdFusion Developer • Certified ColdFusion Instructor • Presenter at DevCon 2000 in DC • Founder and Manager of Central Pennsylvania ColdFusion User Group • Former member of Allaire Consulting Services
Overview • Understanding the Main Concepts • N-tier Applications • CFC’s • N-tier Architecture • Using CFC’s • Examining a Sample Application • Discussion
The Main Concepts • N-tier Architecture • Logical Structure • Division of the App on a conceptual level • Physical Structure • Directory Structure • Server Clustering
The Main Concepts (cont’d) • CFC’s • What are CFC’s? • Based on Object Oriented Concepts • Leverage the Strengths of OO Programming • When do you use CFC’s? • Business Logic • Data Access
N-tier Architecture • Logical Structure • Presentation - UI • Process – Business Logic / Validation • Data – RDBMS / Stored Procs / Queries • Physical Structure • Form meets Function / CFC Packaging • Directory Structure • Server Environment
CFC’s • What are CFC’s? • CFC = “ColdFusion Components” • CFC’s are ColdFusion files, with one notable exception – they must have an extension of CFC • Reusable ColdFusion based objects that facilitate code encapsulation and reuse
CFC’s (cont’d) • Use CFC’s when you need to: • Separate content or data from presentation code • Write business logic and data calls that are accessible by multiple front-end • Check for required parameters or validate parameter data types
CFC’s (cont’d) • CFC Terminology • Methods equate to CFFUNCTION tags, which encapsulate individual functions or uses for the code within them • Arguments are parameters that are passed into the CFC • Return Values are the values passed out of a processed method
CFC’s (cont’d) • Writing CFC’s • CFCOMPONENT <cfcomponent> <cffunction name="authenticate" access="public" output="false"> <cfargument name="user" type="string" required="true"/> <cfargument name="passwd" type="string" required="true"/> <cfquery name="checkAuthentication" datasource="SecurityDB"> SELECT username FROM Security WHERE username = ‘#arguments.user#’ AND password = ‘#arguments.passwd#’ </cfquery> <cfif checkAuthentication.recordCount> <cfreturn checkAuthentication.user/> <cfelse> <cfreturn false/> </cfif> </cffunction> </cfcomponent>
Invoking CFC’s • Using CFINVOKE • CFOBJECT or CFSCRIPT <cfinvoke component="hogs_app._components.tally" method="get_user_tallies" userid="#url.uid#" returnvariable="getUserTallies"> </cfinvoke>
CFC’s (cont’d) • CFC Packaging • Package by Process • Refers to more than just saving them in the same directory • Package name from Custom Tag directory or webroot • By being aware of CFC packaging, you can invoke “package-accessible” methods within another CFC in the package
Examining a Sample Application • HogTallied Example • Security • Tallies • Games • Predictions