Init() function in ColdFusion

init() is just a standard convention most people adopt with components. The init() function initializes any variables needed by the component's functions. Then returns a reference to the current component.
ie
  1. Test.cfm
  2. <cfset myObj = createObject("component", "MyComponent").init(dsn="My DSN")>
  3. MyComponent.cfc
  4. <cfcomponent>
  5. <cffunction name="init" output="false" returntype="MyComponent">
  6. <cfargument name="dsn" type="string">
  7. <!--- initialize variables used within this component --->
  8. <cfset variables.dsn = arguments.dsn>
  9. <!--- return a reference to this component --->
  10. <cfreturn this>
  11. </cffunction>
  12. </cfcomponent

Comments

Popular posts from this blog

What is the difference between asynchronous and synchronous execution?

Yahoo accepting requests for inactive email IDs

Tum Hi Ho Lyrics