Please note, new blog at http://www.acheron.org/darryl/

Utility methods with application.cfc (updated)

I was mucking around with the application.cfc the other day, and I found the following to be true. If you use the onRequest method, and CFINCLUDE the target page, every method you define within the application.cfc will be copied into the variables scope of the included template. This feature of course has been around for ages (reintroduced with one of the MX updaters I believe). Just recently, Sean Corfield posted a link on the CFCDEV list to the LiveDocs, which explained it in more detail:
If your Application.cfc implements the onRequest method, any utility functions that you define in Application.cfc are also directly available in to the target page, because Application.cfc and the target page share the Variables scope. If your application requires utility functions that are used by multiple pages, not just by the methods in Application.cfc, and you do not use an onRequest method, Macromedia recommends that you put them in a separate CFC and access them by invoking that CFC. As with other ColdFusion pages, Application.cfc can access any CFC in a directory path that is configured on the ColdFusion MX Administrator Mappings page. You can, therefore, use this technique to share utility functions across applications....

» Post a Comment