Shaun Mccran

My digital playground

25
M
A
R
2010

Pre loading object (CFC) references in your Application.cfc

One of the best practices that I've been using more and more is ColdFusion's ability to add CFC object references to scopes. By this I mean that it is possible to create a shorter friendlier scoped variable that you use to reference your CFC's.

In your Application.cfc you can map out all your CFC references, this gives you a much shorter variable name to type each time, and it caches the CFC.

view plain print about
1<cffunction name="onApplicationStart">
2
3<!--- scope out all the objects as application level vars --->
4<cfset application.formObj= createObject('component','dir.objName ')>
5<cfset application.siteObj= createObject('component','dir.objName')>
6<cfset application.mailObj= createObject('component','dir.objName')>
7<cfset application.config=createObject('component','dir.objName').getConfig(id=N)>
8
9</cffunction>

Put any references like this in the 'onApplicationStart' function. You do not need to lock the scope in this function, and if the code within it does not run successfully then it does not continue running the application. It will try again on the next page request.

The caching functionality here is great, not only will Coldfusion create a handy short name for CFC, but it will actually run through the code, and stop on any errors. If you deliberately introduce a code error into one of your objects you will see the Application halt and show you the error. For me this is reason enough to move all my business logic into CFC's. This essentially means that it is not possible for a user to get part of the way through a application and find an object based error.

Using this in conjunction with a framework such as FuseBox allows you to load, parse and cache the CFC object, all before your actual display layer has been invoked.

The example below uses the FuseBox function 'onFuseboxApplicationStart' of starting an Application.

view plain print about
1<cffunction name="onFuseboxApplicationStart">
2    <cfset super.onFuseboxApplicationStart() />
3<!--- scope out all the objects as application level vars --->
4
5<cfset application.formObj= createObject('component','dir.objName ')>
6<cfset application.siteObj= createObject('component','dir.objName')>
7<cfset application.mailObj= createObject('component','dir.objName')>
8<cfset application.config=createObject('component','dir.objName').getConfig(id=N)>
9
10
11</cffunction>

Changing the 'fusebox_parameters.mode' value allows you to set this caching at an environmental level, so no caching for development, or caching for live

view plain print about
1<cfset FUSEBOX_PARAMETERS.mode = "development-full-load">
2Or
3<cfset FUSEBOX_PARAMETERS.mode = "production">

12
M
A
R
2010

Integrating Google search into your site using ColdFusion and XML

Rather than writing a custom search, and indexing service for your sites you can use Google to do the leg work for you.

This article examines how you can create and integrate a Google site search into your site. We will query Google and return an XML packet, which we will translate and display within our sites framework.

[ More ]

26
F
E
B
2010

Combining persistent server side (ColdFusion) variables with client side (JQuery) values

I stumbled upon an interested dilemma recently whilst building a search engine. The results of a search are returned, and can be viewed in a list or thumbnail view. The view toggle is a uses a JQuery function, so no persistent data is stored concerning a users current viewing option. The dilemma is how do you maintain the viewing mode across page reloads, such as for pagination, or filtering of the search results?

[ More ]

08
J
A
N
2010

Windows 2003 Server does not stream F4V videos - adding mime types

With the introduction of Adobe's new .F4v flash wrapper you may find that your server does not respond well to files of the .f4v extension. Mine has been returning a 404 error, despite the file being in the right location.

This appears to be a Mime type error, rather than any coding error. Your server simply does not know what type of file the .f4v is, so we need to tell it.

  • On the Windows 2003 server, open the Internet Information Services Manager.
  • Expand the Local Computer Server.
  • Right-click the local computer server and select Properties.
  • Select the MIME Types tab.
  • Click New and enter the following information:

    view plain print about
    1Associated Extension box: .F4V
    2MIME Type box: video/mp4

  • Click OK

You must then restart the World Wide Web Publishing service, as changes do not take effect until the service is refreshed. At this point you should have working .f4v flash movies.

_UNKNOWNTRANSLATION_ /