Wednesday, 10 October 2007

A typical website structure (Coldfusion)

Some people, reading this post have asked to me how organize a site structure for Coldfusion projects. The approach is the same that I have used with a general PHP project:



How you can see, conceptually is the same of a PHP web project; the difference is the Application.cfm file that replaces config.php. This file is usefull to define the coldfusion application's profile and global variables.

We open Dreamweaver and we create a file called Application.cfm in the site root. We open the file and, in the code view, we cancel all dreamweaver default code. Now we have an empty page and we copy and paste the following code:

<cfapplication sessionmanagement="yes" setclientcookies="yes" name="myApplicationName">
<cfset dbName="myDatabaseName">
<cfset thisPage=GetFileFromPath(GetTemplatePath())>
<cfset queryString=Iif(CGI.QUERY_STRING NEQ "",DE("?"&(CGI.QUERY_STRING)),DE(""))>


Coldfusion <cfapplication> tag, defines the scope of a ColdFusion application; enables and disables storage of Client variables; specifies the Client variable storage mechanism; enables Session variables; and sets Application variable timeouts.

The dbName variable store the database name and ca be used into <cfquery> tag.

The thisPage variable, store the current path when an user visit a page (for ex. index.cfm). It's usefull, for example, when you submit a form that reload the same page and execute some coldfusion code. You can replace the file name for example (insertpost.cfm) whith #thisPage#

The queryString variable get the current URL variable name, if is defined an URL variable in the browser navigation bar.

At this moment, our Application.cfm file no require other lines of code.

Conceptual design for index.cfm page layout using CSS is the same I have explained in this post.

No comments:

Post a Comment