Using component packages

Components stored in the same directory are members of a component package. Component packages help prevent naming conflicts, and facilitate easy component deployment; for example:

To invoke a packaged component method using the cfinvoke tag:

  1. In your web root directory, create a directory named appResources.
  2. In the appResources directory, create a directory named components.
  3. Copy the tellTime2.cfc file you created in Invoking methods of a CFC instance and the getUTCTime.cfm file that you created in Putting executable code in a separate file to the components directory.
  4. Create the timeDisplay.cfm file with the following content and save it in your web root directory:
    <!--- Create the component instance. --->
    <cfobject component="appResources.components.tellTime2" name="tellTimeObj">
    <!--- Invoke the methods. --->
    <cfinvoke component="#tellTimeObj#" method="getLocalTime"
    	returnvariable="localTime" >
    <cfinvoke component="#tellTimeObj#" method="getUTCTime"
    	returnvariable="UTCTime" >
    <!--- Display the results. --->
    <h3>Time Display Page</h3>
    <cfoutput>
    	Server's Local Time: #localTime#<br>
    	Calculated UTC Time: #UTCTime#
    </cfoutput>
    

    You use dot syntax to navigate directory structures. Place the directory name before the component name.

  5. Browse the timeDisplay.cfm file in your browser.

The following example shows a CFScript invocation:

<cfscript>
helloCFC = createObject("component", "appResources.components.catQuery");
helloCFC.getSaleItems();
</cfscript>

The following example shows a URL invocation:

http://localhost/appResources/components/catQuery.cfc?method=getSalesItems

View comments in LiveDocs