COLDFUSIONMX Programming Guide COLDFUSIONMX Programming Basics _coldfusion

Source: Internet
Author: User
Tags documentation microsoft sql server odbc web services access database

Phase III: Getting Started with COLDFUSIONMX programming


Preface

In the previous issue we explained the basic management of COLDFUSIONMX, and became familiar with the Coldfusionmx management interface layout, and at the end of the last issue we demonstrated two very short coldfusion programs, which explain ColdFusion's introductory programming in detail, These include database operations that are very frustrating for beginners in ASP.

Before each start, the preface to each issue will introduce you to some coldfusion development or some other valuable little knowledge, the first phase of the Macromedia MX product strategy and COLDFUSIONMX in the Product policy location, While the second issue introduced the COLDFUSIONMX version of the difference, then this issue of the preamble let us know what? About the development of ColdFusion.

1995 is a memorable time, because what happened in that year was the last century, and not just so much. If old-age developers recall, that time the web was the world of HTML and CGI, static pages are HTML, and dynamic programs are more than 90% CGI, as I remember. A pair of brothers Allire in the United States, in order to solve the problem of database access for their clients, feel the difficulty of writing and maintaining CGI programs is intolerable. So, with the computer talent Jeremy Allire in 1995 years wrote a fast response and easy to write dynamic scripting language, called ColdFusion, once launched, it shook the entire network industry. Later, the brothers saw the development of ColdFusion, then set up a Allire company (later Macromedia Acquisition). Over the next few years, half of the world's top 500 have adopted ColdFusion to solve the company's different problems. Through continuous revisions and growing developers, ColdFusion later developed as the industry's leading enterprise-class solution development preferred. Now, in order to unify the product line, in order to unify the industry standard, in order to fully compatible with the Java platform, Macromedia released the Coldfusionmx. The word "Neo", which is often seen by the Macromedia, is the encoded name for the development industry solution that uses the next generation of ColdFusion.

If you see the word Neo, it is not difficult to understand Macromedia's ardent expectation for Coldfusionmx, the name of the hero in the famous movie "Matrix" is also called Neo. The similarities are just the authors ' own speculations. OK, no more chat, enter the topic of our issue.


The first part COLDFUSIONMX Basic tag programming

The author has read a lot of English and Chinese textbooks, that the most effective way is to refer to the example of the Code section to cooperate with the explanation of the most outstanding process. Therefore, for each coldfuiosn tag, the author does not intend to repeat one by one, your friends can see through some reference to understand all the tag function and grammar. For standard documentation, refer to the official documentation included in the Administrator admin interface after you install COLDFUSIONMX.

So what kind of way does the author use to help a friend who wants to learn coldfusionmx to quickly enter the realm of writing code? If the use of all the tag all in accordance with the order to explain, it will cause the interest of learners to different degrees of decline. You may know the relationship between DREAMWEAVERMX and Coldfusionmx in the Macromedia MX in the previous tutorial. The launch of DREAMWEAVERMX is a perfect tool for developing COLDFUSIONMX applications, as it integrates the previous ColdFusion Studio, Ultradev, Dreamweaver, HomeSite Four products of the main function in one, so, only use dreamweavermx to make static pages, can be said to use only less than One-third of the function. So, the tutorials in this series start with the development Coldfusionmx program features integrated in DREAMWEAVERMX, so that you can learn how to develop COLDFUSIONMX programs in Dreamweavermx, And then provide you with the skills to use COLDFUSIONMX to develop advanced applications.

Open the Dreamweavermx interface to see the shortcut object panel on the top right, where the following three object panels are CFML Basic, CFML flow, CFML Advanced, and this tutorial begins with CFML Basic.

When CFML Basic is selected, the following icon arrangement appears:

Then the left to right icons represent cfservervariables, CFQuery, Cfoutput, Cfinsert, Cfupdate, Cfinclude, Cflocation, Cfset, cfparam, annotations, variable symbols, Cfscript. Our tutorials also start with Cfset. Because it is the simplest and most important tag in the coldfusionmx.

When you click the icon, the following code snippet appears: <cfset, the Cfset label is the unique label for the variable set in ColdFusion. In ColdFusion, each unique tag that is explained by CFMX server is preceded by CF, such as Cfset, Cfquery, and so on. and Cfset's standard syntax format is:

The left side of the equal sign represents the variable name, and the value of the variable on the right. Quite simply, if you want to create a variable called VAR1, assign it to hello,friend!, then you need to write your program code like this:

<cfset var1= "hello,friend!" >

So if you want to set up Chinese, just write it:

<cfset var1= "Hello, friend!" ">

Then, when you set a value for your variable, you don't need to add double quotes around the value of the variable. Like what:

<cfset pi=3.1415926>. In addition, cfset the role of this tag can also be numerical operations and dynamic transfer of variables. The encoding for numerical calculations and variable jumps is also very simple, see the following code fragment:

<cfset pi=3.1415926>

<cfset number_1=pi*10>

<cfset number_2=number_1>

I want to have a little program experience friends on the above code understanding should not be a problem, it executes a PI value of the assignment, as well as the PI variable multiplication, the result assigned to number_1, finally, the number_1 variable results point to the variable number_2.

In addition, Cfset has another use, let's take a look at:

<cfset var1= "Test" >

<cfset "#var1 #" = "hello!" >

<cfoutput> #test #</cfoutput>

What is the result output? The answer is: hello! this string. The reason is simple, hello! this string is paid to a variable called "#var1 #", which is equivalent to test, that is, test the string automatically becomes a variable name.

Click the icon, the exclamation mark tag is cfparam, this tag's basic function and Cfset is consistent, but also for variable assignment, then it and cfset what difference? The difference is to check if a variable exists, and if so, give a default value. Look at the property settings window that appears after clicking on it:

As you can see in the previous illustration, Cfparam has three properties, that is, name, default, and Type,name represent the names of the variables, default is the initial value of the variable, the defaults are empty, type represents the type of the variable, and CFMX sets the following types for Cfparam:

The variable type already covers the type of variable that we can use to encode the coldfusion. Cfparam This tag information can be clicked on the Property Settings window tag info to understand the detailed use of the method, and later other tags can also be in the Properties window by clicking on the tag info to understand. Then, after you set up Cfparam, the following lines of code appear:

<cfparam name= "Url.id" default= "1" type= "any" >

This line of code is equivalent to:

<cfif not Definede (url.id) >

<cfset url.id=1>

</cfif>

To determine whether the variable exists, if it does not, give a value of 1 url.id. This feature is often used in the development of the registration and verification module with Cfform this tag to use, the following tutorial will be seen.

Click on the icon to add ColdFusion-specific annotation notation to your CFM page:<!---content---, for example:

<!---

Set a variable named Var_hello

--->

The above code is ignored in the process of the interpretation of. CFM by the CF server, and good annotation habits are necessary to develop large-scale and complex applications, and the qualities that a good developer should have.

Click on the icon to show the # #标记 that you often encounter in the. cfm file, so that it displays the results of the variables in the ColdFusion, like the previous program:

<cfset var1= "Test" >

<cfoutput> #var1 #</cfoutput>

is to display the value of the VAR1 variable.

Click the icon to add a unique coldfusion Server variable to the page. Dreamweavermx popped out of the interface is:


The following kinds of server variable are supported by CFMX:

The following is a brief introduction to the variables often used in server variables. The Server variables is a CGI variables in ColdFusion. It uses the server-side common Gateway interface variable. While CGI is a common form of scripting, COLDFUSIONMX also supports some variant formats that are unique to cgi-bin.

Http_referer: Determine which URL the viewer comes from

Http_user_agent: To determine the type of browser used, currently popular in several browsers can be identified.

Query_string: That's. cfm? The information that came with the following parameters.

REMOTE_ADDR: The IP address of the visitor

Other variables you can learn by looking at official reference, and there's no more to repeat.

Let's take a look at this piece of code:

<cfoutput>

How are you doing!

Your browser is #cgi. http_user_agent#!

</cfoutput>

The results show the author's own browser version:

Your browser is mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)!

Click the icon to use the most commonly used tag:cfquery in ColdFusion. This tag is used to complete the database query.

Before beginning to explain the database query, the author himself to the vast number of developers to mention a wake up, I hope you use coldfusionmx for development, try to avoid access and MySQL, because these two databases and coldfusionmx information interaction will appear more or less Chinese problems , I want you to use SQL Server database or Oracle. Of course, using Access or MySQL for English processing is certainly no problem. Early coldfusion5 in processing databases, access, and other small databases do not have a Chinese problem, perhaps because the ColdFusion core code was rewritten, JDBC corresponding Chinese problem came out, but believe that Macromedia will soon fix the problem. The author himself in the use of cfquery, for the convenience of explanation, will use the Access database, but the subsequent use of Chinese to change the database records of operations will be turned to SQL Server, please note.

How to solve the Chinese problem, please refer to the information here:

http://www.flashempire.net/showthread.php?s=1871e826d3945c355df09e5ef8190a6e&threadid=120844

After clicking on the cfquery tag, the DWMX interface appears:

The picture above is about setting the Cfquery window, the three parts of the red rectangle on the left side of the graph can be set to different levels of detail for the cfquery, General is our longest-used setting, and connection is the connection setting, Some of the properties of general connection can be determined directly through the DataSource settings in the CFMX administrator. Persistent queries represents a constant query that can be invoked from the cache. The following is the standard syntax for cfquery:

Where the name attribute is necessary, is to give you the definition of cfquery a name, in the future when you want to call this name property value to find the relative query. DataSource is the name of the data source from which the query originated, and the name of the data source is set CFMX administrator. There is a need to insert a method for setting up a data source. Open the CFMX Administrator admin interface, click Data & Services, and then see the right area of the admin interface where the CFMX administrator has defined the source, the screenshot below:

The figure above represents 1 of the database driver with Microsoft Access, and the 2-box selection is two names of data sources that are set up through Windows ODBC, and the data is driven by Windows ODBC sockets. The area selected by the 3 box is the data source defined using Microsoft SQL Server drivers. Setting up an Access database is a very easy thing to do, first of all, your Access database can be placed anywhere on your local hard drive, not necessarily in a webserver directory, and then, from the image above, you can add new data Source to fill in the name of the data source you want, name as long as the standard string is OK, can not start with a number. Then, from the Driver drop-down option, select Microsoft Access Driver and click Add to enter the detailed Setup page:

Basically, you don't have to set any advanced options for an Access database, but if you need to, for example, restrict the operation of the database, click Show advanced Settings to modify it. The cfsnippets in the figure above is the default case database after the installation of Coldfusionmx, just like the software of access, automatically has the Northwind this library. The following cfquery examples are mainly cfsnippets. Instead, SQL Server only adds a few more steps, first of all, to populate SQL Server's database name when you set up a data source for SQL Servers, and second, to enter the IP that is located on the server, use localhost on the computer, and most importantly , you must enter a username and password that has access to the database, and the author recommends setting a specific username and password in SQL Server instead of using the default SA account.

Back to the Cfquery property description, other properties are not required attributes. A description of the attribute can refer to the COLDFUSIONMX reference manual.

Let's take a look at a simple cfquery code:

<cfquery name= "test" datasource= "Cfsnippets" >

SELECT *

From Employees

ORDER BY emp_id

</CFQUERY>

<cfoutput query= "Test" >

#Emp_ID # | #FirstName # | #LastName # | #EMail # | #Phone # | #Department # <br>

</cfoutput>

What was the result? Take a look at the screenshot below:

Surprisingly, the!!! can be recycled. Number of CF code, only a few lines, and asp,jsp,php to complete the same effect, need to write a few lines of code? It must be known to everyone who has used it.

Look at the Cfquery code for a complex point:

<cfquery name= "QueryName" datasource= "Cfsnippets" >

SELECT *

From Employees

WHERE LastName = ' Peterson '

</cfquery>

<cfoutput> #queryname. firstname# <br>

#queryname. lastname# <br>

#queryname. department# <br>

#queryname. recordcount# <br>

#queryname. currentrow# <br>

#queryname. columnlist#

</cfoutput>

<cfquery name= "QueryName" datasource= "Cfsnippets" >

SELECT *

From Employees

</cfquery>

<table border= "1" >

<tr>

<td> last Name </td>

<td> A-Name </td>

<td> Department </td>

</tr>

<cfoutput query= "QueryName" >

<tr>

<td> #LastName #</td>

<td> #FirstName #</td>

<td> #Department #</td>

</tr>

</cfoutput>

</table>

So the result is screenshot below:

We first select a piece of information about Perterson this employee, and then list all the employees ' information. The second is to use Queryname.recordcount to view the number of records, with Queryname.currentrow to see the current record is in the database of the first few, with Queryname.columnlist to represent the database column of a sort. Finally, we also see that a few lines of code let the entire employee table of data in the HTML table loop output, do you already feel coldfusion simple and quick? More surprising features are available in future tutorials, including the built-in Full-text search engine, generator Data driven flash (image), CF component, and Web services.

The next tutorial goes on to explain CF basic tag programming, including the Cfinsert of manipulating databases, the use of cfupdate;cfinclude and cflocation tags, and how to write ColdFusion founction. OK, everybody, let's see you in the next issue.


Discussion on the second part of forum ColdFusion

how to get the developer version of the Coldfusionmx

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=116459

Coldfusionmx First Security vulnerability

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=121286

Coldfusionmx Enterprise Standard Documents

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=121621

Coldfusino MX Learning Experience

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=120616

CFMX Chinese Problem Solving method

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=120844

How to change Coldfusionmx the Port

http://www.flashempire.net/showthread.php?s=783cb977b6551d6a2dc52c87555e0208&threadid=118258

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.