Lost Password?

Go Back   CodeCall Programming Forum > Web Development Forum > ASP, ASP.NET and Coldfusion

ASP, ASP.NET and Coldfusion Microsoft's Web Development Language (ASP/ASP.NET) and Coldfusion discussion

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-04-2006, 08:17 AM
Kaabi's Avatar   
Kaabi Kaabi is offline
Programming God
 
Join Date: Jul 2006
Posts: 884
Rep Power: 13
Kaabi is on a distinguished road
Default Coldfusion Example Code

I want to see how Coldfusion looks, and compare it to other web programming languages. I saw a bit of it in another topic, but I want to see an extended example. Thanks.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 07-08-2006, 12:07 PM
DevilsCharm's Avatar   
DevilsCharm DevilsCharm is offline
Programming God
 
Join Date: Jul 2006
Posts: 887
Rep Power: 13
DevilsCharm is on a distinguished road
Default

Well, here's how you say "Hello World":

<cfset variable = "Hello World">

<cfoutput>#variable#</cfoutput>

Pretty simple, at least, more simple than something like C++ (although that's a competely different language).
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-12-2006, 12:14 PM
falco85 falco85 is offline
Programmer
 
Join Date: Apr 2006
Posts: 105
Rep Power: 9
falco85 is on a distinguished road
Default

wow, that looks like XML or HTML. Got any more code you could show? I'm interested in learning more about it.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 12-09-2006, 03:58 AM
Fischerspooner's Avatar   
Fischerspooner Fischerspooner is offline
Newbie
 
Join Date: Dec 2006
Posts: 27
Rep Power: 7
Fischerspooner is on a distinguished road
Default

Querying a DB.
Code:
<cfquery name="myQuery" datasource="yourODBCdatasource">
   SELECT * FROM table
</cfquery>

<!--- now show me all the records from the query  --->
<cfoutput query="myQuery">
#field1# - #field2# - #field3#
</cfoutput>
We use it at work for our intranet
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 12-12-2006, 08:36 AM
Lop's Avatar   
Lop Lop is offline
Speaks fluent binary
 
Join Date: May 2006
Posts: 1,135
Rep Power: 16
Lop is on a distinguished road
Default

Looks a lot like HTML
__________________
Lop
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 12-13-2006, 09:04 AM
TcM's Avatar   
TcM TcM is offline
Moderator
 
Join Date: Aug 2006
Location: In a technologic world :p
Posts: 7,351
Rep Power: 67
TcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud ofTcM has much to be proud of
Default

Yeah I agree.. a little it seems a cool language to learn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 04-12-2007, 02:00 PM
WillB's Avatar   
WillB WillB is offline
Learning Programmer
 
Join Date: Apr 2007
Location: St. Cloud, Fl
Age: 19
Posts: 43
Rep Power: 6
WillB is on a distinguished road
Default

Quote:
Originally Posted by Tcm9669 View Post
Yeah I agree.. a little it seems a cool language to learn
It can be...

I use Coldfusion in practitcally everything at work, and I must say I enjoy it...

If you take a look at Welcome to the world of Westgate Resorts - WestgateResorts.com
Most of the site is written in Coldfusion.

Also, MySpace is written (well part of it...) in Coldfusion also. But that isn't really the best example...

It can be a great tool to use, however it is pretty expensive.

Currently the most mature framework out there is Fusebox. However others exist that have potenial in the future as well...

The bonus with CFML is that it isn't a compiled language, but an Interpreted Language. That means that HTML can be written in a Coldfusion file (*.cfm) and it will work.

Here is a extended example of a functions file we use:

Code:
<!-----------------
   Global Functions
------------------>
<cffunction name="makeHeader"
            hint="Makes page headers, wrapping the header in standard HTML for this web site">
   <cfargument name="header"
               required="true">

   <cfset var returnContent = "">

   <cfoutput>
      <cfsavecontent variable="returnContent">
         <table class="boxHeader"
                width="550"
                border="0"
                cellpadding="3"
                cellspacing="0">
            <tr>
               <td class="boxHeader">
                  #header#</td>
            </tr>
         </table>
      </cfsavecontent>
   </cfoutput>

   <cfreturn returnContent>

</cffunction>

<cffunction name="wrapTable"
            hint="Wraps content in a standard style table for this web site.">
   <cfargument name="content"
               required="true">
   <cfargument name="header"
               required="true">

   <cfset var returnContent = "">

   <cfoutput>
      <cfsavecontent variable="returnContent">
         <table width="550"
                class="form"
                cellpadding="5"
                cellspacing="0"
                border="0">
            <tr>
               <td class="boxHeader">
                  #header#</td>
            </tr>
            <tr>
               <td bgcolor="##D1DFEC" width="529" valign="top">
                  #arguments.content#</td>
            </tr>
         </table>
      </cfsavecontent>
   </cfoutput>

   <cfreturn returnContent>

</cffunction>

<cffunction name="getRenderer"
            hint="Factory method for Renderer objects for the form style of this web site">
   <cfargument name="width"
               required="false"
               default="525">

   <cfscript>

      var renderer = getSAMSFormBuilder().getOverUnderRenderer(arguments.width);
      renderer.setCellPadding(3);
      renderer.setSubmitButtonAlignment(renderer.RIGHT);
      renderer.setErrorMessageStyle("formError");
      renderer.setRequiredSymbolStyle("requiredSymbol");

      return renderer;

   </cfscript>

</cffunction>

<cfscript>

   // Factory method for Form objects
   function getForm(name)
   {
      var theForm = getSAMSFormBuilder().getForm(name);
      theForm.setSubmitButtonImageURL("images/but_continue.jpg");
      theForm.useSubmitButtonImageOnRender(true);

      return theForm;
   }

   // Factory method for Formatter objects
   function getFormatter()
   {
      return CreateObject("component", "com.westgateresorts.web.Formatter");
   }

   // Factory method for SAMSFormBuilder objects
   function getSAMSFormBuilder()
   {
   	return application.G_SAMS_FORMBUILDER;
   }

   // Converts return characters in plain text to HTML <br> tags
   function plainTextToHTML(convertString)
   {
      return Replace(convertString, Chr(10), "<br>", "ALL");
   }

   // Standard Fusebox JSP forward function
   function fuseboxForward(XFA, attributesScope)
   {
      GetPageContext().forward("#request.G_SELF_FUSEACTION##XFA#&#attributesToURLString(attributesScope)#");
   }

   // Standard attributes to URL encoded string function
   function attributesToURLString(attributesScope)
   {
      var returnValue = "";
      var listOfKeys = StructKeyList(attributesScope);
      var listArray = ListToArray(listOfKeys);

      for (i = 1; i LTE ArrayLen(listArray); i = i + 1)
      {
         if ((CompareNoCase(listArray[i], 'FIELDNAMES') NEQ 0) AND (CompareNoCase(listArray[i], 'FUSEACTION') NEQ 0))
         {
            returnValue = returnValue & listArray[i] & "=" & URLEncodedFormat(StructFind(attributesScope, listArray[i])) & "&";
         }
      }

      // Trim trailing ampersand
      if (Len(returnValue) gt 0)
      {
         returnValue = Mid(returnvalue, 1, (Len(returnValue) - 1));
      }

      return returnValue;
   }

   // Adds BreadCrumb objects to the global breadcrumb stack for this page request
   function addBreadCrumb(newBreadCrumb)
   {
      ArrayAppend(request.G_BREADCRUMB, newBreadCrumb);
   }

   // Factory method for BreadCrumb objects
   function breadCrumb(BCText, BCLink)
   {
      return CreateObject("Component", "objects.BreadCrumb").init(BCText, BCLink);
   }

   // Factory method for WGRMenu object
   function getWGRMenuObject()
   {
      return CreateObject("Component", "objects.WGRMenu");
   }

   // Renders the BreadCrumb objects on the global breadcrumb stack for this page request
   function renderBreadCrumb(breadCrumbArray)
   {
      var returnString = "";
      var currentBreadCrumb = "";
      var currentText = "";
      var currentLink = "";
      var finalText = "";

      for (i = 1; i lte ArrayLen(breadCrumbArray); i = i + 1)
      {
         currentBreadCrumb = breadCrumbArray[i];
         currentText = currentBreadCrumb.getText();
         currentLink = currentBreadCrumb.getLink();

         if ((currentLink eq "") or (i eq ArrayLen(breadCrumbArray)))
         {
            finalText = currentText;
         }
         else
         {
            finalText = '<a href ="' & currentLink & '">' & currentText & "</a>";
         }
         if (returnString eq "")
         {
            returnString = "&nbsp;" & finalText;
         }
         else
         {
            returnString = returnString & " | " & finalText;
         }
      }

      return returnString;
   }


   function populateSelectListWithDestinations(selectListObject)
   {
      var currentDestination = "";
      var destinationName = "";

      // Get all of the resort destinations
      var resortDestinations = application.G_WGRESORTS.getResortLocations();

      // Go through all the resort local destinations
      for(i = 1; i lte ArrayLen(resortDestinations); i = i + 1)
      {
         // Get the destination at the i-th location and prepare the name
         currentDestination = resortDestinations[i];
         destinationName = (currentDestination.getTwoLetterState() & " - "  & currentDestination.getName());

         // Add the name of the i-th destination to the select list object
         selectListObject.addOption(destinationName, destinationName);
      }
   }

</cfscript>

<cffunction name="getWestgateResortsObject"
            access="public"
            output="false"
            returnType="com.westgateresorts.wgr.WGResorts"
            hint="Returns a reference to the global WGResorts component">

   <cfreturn application.G_WGRESORTS>
</cffunction>

<cffunction name="getHotWeeksPhone"
            access="public"
            output="false"
            returnType="string"
            hint="Returns the phone number displayed on the Hot Weeks page.">

   <cfreturn application.G_HOTWEEKS_PHONE>
</cffunction>

<cffunction name="getGoogleAnalyticsCode"
            access="public"
            returnType="string"
            hint="Outputs google analytics code according to the environment settings.">

   <cfset var googleAnalyticsEnabled = application.G_GOOGLE_ANALYTICS_ENABLED>
   <cfset var returnContent = "">

   <cfoutput>
      <cfsavecontent variable="returnContent">
			<cfif googleAnalyticsEnabled>
				<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
				</script>
				<script type="text/javascript">
				   _uacct = "UA-758430-2";
				   urchinTracker();
				</script>
			</cfif>
      </cfsavecontent>
   </cfoutput>
   
   <cfreturn returnContent>

</cffunction>
Something that other people haven't stated yet, is that Coldfusion also offers <cfscript> which resembles Java Syntax.
__________________
Everything in Life can be solved with an 'If/Else' statement.

Life is like one big try/catch statement, nested within a loop.

-Will


Last edited by WillB; 04-12-2007 at 03:13 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Code: Capture Code from USB Camera MrNobody VB Tutorials 46 08-30-2008 01:01 PM
PHP Code: Simple Encryption Algorithm Void PHP Tutorials 4 04-19-2008 09:52 AM
Basic Calculator AfTriX VB Tutorials 3 02-29-2008 08:53 AM
Where to Put PHP Code clookid PHP Tutorials 1 01-11-2007 08:44 PM


All times are GMT -5. The time now is 09:51 AM.

Contest Stats

GoogleKeyw ........ 20.00000

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 67%

Ads