1 / 33

ColdFusion Basics

ColdFusion Basics. 321483 02-05-2002. Working With Templates. CFML Reference: Online reference to all CFML tags http://nongmon.compsci.buu.ac.th/cfdocs/CFML_Reference/contents.htm. Working With Templates. Templates are ColdFusion Application Pages (programs)

dafydd
Télécharger la présentation

ColdFusion Basics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ColdFusion Basics 321483 02-05-2002

  2. Working With Templates • CFML Reference: • Online reference to all CFML tags http://nongmon.compsci.buu.ac.th/cfdocs/CFML_Reference/contents.htm

  3. Working With Templates • Templates are ColdFusion Application Pages (programs) • All ColdFusion Code is written: • Inside tags • or within the boundaries of paired tags (just like HTML)

  4. Working With Templates • CFML Tags • CFML tags are written in the same manner as HTML tags but they start with CF • Syntax of most CFML tags: <CFTagName> … </CFTagName>

  5. Working With Templates • CFML Tags • Any CFML tag that doesn’t have or require end tag may optionally be written as follow: <CFTagName> • Most CFML tags accept one or more attributes that affect tag’s behavior

  6. Working With Templates • Creating Templates • See Demo With ColdFusion Studio and Practice Support Document • Saving Templates • In Windows Environment, filenames are case-insensitive • On Unix, filenames are case-sensitive • See Demo With ColdFusion Studio and Practice Support Document

  7. Working With Templates • Executing Templates • Type your template URL in the Browser • See Demo

  8. Commenting Your Code • ColdFusion comments begin with tag<!--- and end with tag ---> • Good practice to use comments to provide explanation of your code

  9. Commenting Your Code • HTML-style Comments: • <!- - Your comments - -> • CFML Comments: • <!- - - Your comments - - ->

  10. Using Variables • Variable: • Name associated with a data value • A variable stores or contains a value • In ColdFusion, you don’t have to declare explicitly your variables

  11. Variables and CFSET • <CFSET> Tag: • <CFSET> tag is used to create and assign a value to a variable • Example: • <CFSET Price = 1300.00> • Creates a variable named Price which is assigned the value 1300.00 • If the variable Price exists, <CFSET> resets it to the specified value

  12. Variables and CFSET • <CFSET> Tag: • <CFSET> tag can be used to perform computations • Example: • <CFSET Tax = Price * 0.07> • Creates a variable named Tax which is assigned a value obtained by multiplying variable Price by 0.07 • <CFSET> Syntax

  13. Variable Naming Rules • Variable names must begin with a letter, and can be followed with a combination of letters, numbers, or underscores (_) • Variable names must be one word – they can’t contain spaces • Generally accepted naming rules are to capitalize first letter of each word in the variable name • Variable names are not case sensitive: • i.e. TaxRate and taxrate are the same variable • See more information from CFdoc

  14. Data Types and Variable Types • ColdFusion Data Types include: • Integer • Real Number • String • Boolean • Date and Time • Array • Structure • List • Query • COM Object • See more information from CFdoc

  15. Data Types and Variable Types • Variable Type (Variable Scope) • To be covered later • See more information from CFdoc

  16. Working With Expressions • Expressions • ColdFusion expressions consist of operands and operators • Operands are comprised of constants and variables • Operators are the verbs that act on the operands

  17. Working With Expressions • Arithmetic Expressions • Arithmetic expressions are formed by combining values and/or variables and arithmetic operators in an appropriate manner • String Expression • To be covered later

  18. Working With Expression • Examples of Expressions: • <cfset x=7> <cfset y = 1+(x * 5)^x> • <cfset firstname = "Koffi "> <cfset lastname = "N’DA"> <cfset name = firstname & lastname>

  19. Arithmetic Expressions See more information from CFdoc

  20. Operator Precedence • When evaluating expressions ColdFusion uses standard operator precedence

  21. Operator Precedence

  22. Operator Precedence • Example: • 20*5-(4+6)^2/(22\3)MOD6^2=?

  23. CFOUTPUT and Pound Sign (#) • The <CFOUTPUT> tag is used to display the value of a variable on a Web page • Variable may be the result of: • An expression, a database query or other operation • Variable name must be enclosed in # (pound sign) when used with <CFOUTPUT> tag • <CFOUTPUT> replaces the variable with it’s current value when web page is returned to the web browser • Two sided tag: <CFOUTPUT></CFOUTPUT>

  24. CFOUTPUT and Pound Sign (#) • Using Pound Sign (#) • ColdFusion treats text delimited by pound signs differently from plain text • When ColdFusion processes an expression, it replaces the text of the expression and the two pound signs around it with its resulting value • See more information from CFdoc

  25. CFOUTPUT and Pound Sign (#) • Example of How to Use CFOUTPUT and #: • See files home1a.cfm and home1b.cfm located at: http://127.0.0.1/demo/

  26. Using Functions • ColdFusion provides a full set of functions for data formatting, string manipulation, and complex computations • Click the following links for more information on functions: • List of functions • Other information on Functions

  27. Using Formatting Functions • ColdFusion provides functions to format numerical values • DollarFormat(expression): • Formats the expression as a monetary amount • DecimalFormat(expression): • Formats the expression producing 2 decimal places

  28. Using Formatting Functions • NumberFormat(expression, mask): • Formats expression based on rules provided in mask • Mask is a string which contains: 9 – place holder for digit . – specifies location of decimal point , - indicates thousands separator

  29. Arithmetic Functions

  30. Arithmetic Functions

  31. Arithmetic Functions

  32. Using Functions • Examples of How to Use Functions:

  33. Exercise • Open file cfbasic1.doc located in the “Class Exercises” folder on the public directory.

More Related