Baixe learncfinaweek 1 5 e outras Manuais, Projetos, Pesquisas em PDF para Cultura, somente na Docsity!
Week 1
www.learncfinaweek.com
Acknowledgements This course would not have been possible without the following people: Authors Editors Designers
- Emily Christiansen
- Tim Cunningham
- David Epler
- Sam Farmer
- Dave Ferguson
- Simon Free
- Paul Hastings
- Guust Nieuwenhuis
- Dan Skaggs
- Nic Tunney
- Adam Tuttle
- Dan Wilson
- Mark Esher
- Kristin Ferguson
- Tiffany Goebel
- Nick Borden
- Jim Priest Copyright Code licensed under the Apache License v2.0. Documentation licensed under CC BY 3.0.
- Installation
- The Basics
- What is ColdFusion?
- Setting Variables
- Data Types
- Commenting
- ColdFusion Tags vs. ColdFusion Script
- Hands On
- Hands On
- Decision Making and Scopes
- Decision Making
- Scopes
- Hands On
- Hands On
- Hands On
- Hands On
- Looping
- Data Handling
- Databases
- XML
- JSON
- Hands On
- Hands On
- Hands On
- Code Reuse.............................................................................
- Functions
- Including
- Custom Tags
- Components
- Hands On
- Hands On
- Hands On
- Hands On
- Application.cfc
- Request Lifecycle Events
- Time for the Code!
- More than Just Events..................................................................................
- What is an Application?
- Where does Application.cfc go?
- What’s Application.cfm?
- Appendix: Application.cfc Template
- Hands On
- OOP.........................................................................................
- Intro to ORM
- Introduction...................................................................................................
- Configuration
- Working with Data
- Hands On
- Hands On
- Hands On
- Hands On
- Mail
- Configure Mail Settings
- Send Email
- Using CFScript
- View Undelivered Mail
- Settings Overwrite Default Mail Server
- Hands On
- Document Handling
- cfhttp.............................................................................................................
- cfdocument
- cfpdf..............................................................................................................
- cfpdfform
- File Manipulation
- Image Manipulation
- Spreadsheets
- Hands On
- Hands On
- Hands On
- Hands On
- Caching
- Security....................................................................................
- Introduction...................................................................................................
- Injection
- Cross-site Scripting (XSS)............................................................................
- Cross-Site Request Forgery (CSRF)............................................................
- Session Identifier Protection.........................................................................
- File Uploads
- Secure Password Storage............................................................................
- ColdFusion Configuration
- Hands On
- Hands On
- Error Handling and Debugging
- Error Handling
- Debugging
- Hands On
- Hands On
- i18n
- What to do Next
Learn CF in a Week - Week 1 - Installation Page 2
- Select Server configuration and click "Next".
- Leave all checkboxes selected and click "Next".
- Leave the "Enable Secure Profile" checkbox unchecked and click "Next".
- Provide a password and click "Next". Make sure you remember the password!
- Leave the location at C:\ColdFusion10\ and click "Next". If you want to install in a different location you can, but it is important to note that the install instructions will always reference C:\ColdFusion10.
- Select 'Built-in web server (Development use only)' and click "Next".
- Provide a password and click "Next". Make sure you remember the password; you will need this later on in the install process.
- Select 'Enable RDS', provide a password and click "Next". Make sure you remember the password!
- Leave the 'Automatically check for server updates' selected and click "Next".
- Click "Install".
- If you receive any Windows firewall messages, click 'Allow'.
- When the installation wizard is done, keep the 'Launch the Configuration Wizard in the default browser' selected and click "Done".
- A browser window will open. Enter your ColdFusion Administrator Password and click "Login". (This is the password from step 16)
- Once you receive the 'Setup Complete' screen, click the "OK" button.
- You will now see the ColdFusion Administrator screen. To access this screen at a later date, you
Learn CF in a Week - Week 1 - Installation Page 3
Mac
- Open up a web browser and go to: http://www.adobe.com/go/trycoldfusion/
- Sign in with your Adobe ID. If you do not have an Adobe account, click on the "Create an Adobe account" button on the left.
- Select the English | MAC OS X version of ColdFusion.
- Click "Download".
- Save the file to your desktop.
- Once downloaded, double click the file.
- Click "Next".
- Accept the terms and click "Next".
- When you see the screen below, select "Developer Edition" and click "Next".
- Select Server configuration and click "Next".
- Leave all checkboxes selected and click "Next".
- Leave the "Enable Secure Profile" checkbox unchecked and click "Next". can go to: http://localhost:8500/CFIDE/administrator/index.cfm
- You have now successfully installed ColdFusion 10. To access the web root, you can go to: http://localhost:8500/. he web root on the file system is C:\ColdFusion10\cfusion\wwwroot.
Learn CF in a Week - Week 1 - Installation Page 5 Installing MySQL
Windows
ColdFusion has the ability to communicate with a number of different databases, which will be covered later on in this course; for the sample application we will be working on throughout the course, we will be using MySQL. If you already have MySQL 4 or 5 already installed, you can proceed to the 'Install Sample Files' section. If not, follow the steps below:
- Open up a browser and go to: http://dev.mysql.com/downloads/mysql/
- Scroll to the list of available downloads. Click the 'Download' button next to the applicable download. - Windows 64 bit - Windows (x86, 64-bit), MSI - Windows 32 bit - Windows (x86, 32-bit), MSI If you are unsure, assume you are on a 32 bit machine.
- To begin the download, you must either login using pre-existing credentials by clicking the 'Proceed' button under the New Users section or click the 'No thanks, just start my download' link at the bottom of the screen.
- Save the file to your desktop.
- Double click the file.
- On the Welcome screen click 'Next'.
- Accept the terms in the license agreement and click 'Next'.
- When presented with a list of available Setup Types, Select 'Typical'.
- When ready to install, click 'Install'.
- If a system message pops up asking if you want the software to be installed on your machine, click 'Yes'.
- If a MySQL enterprise pop up window appears, click 'Next' until it disappears.
- When the Setup Wizard has completed, Click 'Finish'.
- If you receive another pop up message asking if you want the software to be installed on your machine, click 'Yes'.
- When the Server Instance Configuration Wizard displays, Click 'Next'.
- When displayed the available Server Instance Configuration types select 'Standard Configuration' and click 'Next'.
- When on the Windows Options scree, keep 'Install as a Service' selected as well as 'Launch the MySQL Server automatically'. Select the 'Include Bin Directory in Windows PATH' option and select 'Next'.
Learn CF in a Week - Week 1 - Installation Page 6
Mac
- Open up a browser and go to: http://dev.mysql.com/downloads/mysql/
- Scroll to the list of available downloads. Click the 'Download' button next to the applicable download. - Mac 64 bit - Mac OS X ver. 10.6 (x86, 64-bit), DMG Archive - Mac 32 bit - Mac OS X ver. 10.6 (x86, 32-bit), DMG Archive If you are unsure, assume you are on a 32 bit machine
- To begin the download, you must either login using pre-existing credentials by clicking the 'Proceed' button under the New Users section or click the 'No thanks, just start my download' link at the bottom of the screen.
- Save the file to your desktop.
- Double click the file.
- Once the DMG has mounted, double click the mysql-5.5.28-osx10.6-x86_64.pkg (or similar) file. It should be the first file in the list.
- On the welcome screen, click 'Continue'.
- Review the Important Information screen and click 'Continue'.
- Review the Software License Agreement and click 'Continue'.
- Agree to the terms.
- Select the drive you wish to install the software to and click 'Continue'.
- Click 'Install'.
- Provide your system password and click 'OK'.
- Once you receive the screen stating the Installation was Successful, click 'Close'.
- Double click the MySQL.prefPane icon.
- Click 'Install'.
- If the MySQL server is not running, click the 'Start MySQL' Server button.
- On the Security Options scree, specify a new root password and select 'Next'. Remember this password as it will be needed later!
- When the Ready to Execute screen displays, click 'Execute'.
- After all the Configuration steps have successfully run, Click 'Finish'.
- You have successfully installed MySQL.
Learn CF in a Week - Week 1 - Installation Page 8 Installing Sample Files As well as having the ability to read about ColdFusion, 'Learn CF in a Week' has a Hands On section of the course, giving you the opportunity to create your own ColdFusion web site. During the course, you will take a basic HTML website and add ColdFusion to it, creating a fully functional ColdFusion application. To be able to take part in the Hands On, you must first install the necessary Application files. To do this, follow the steps below:
- Download the sample application files from the download link in the header of http://www.learncfinaweek.com/.
- Create a folder in your web root called 'learncfinaweek'. Your webroot is located at: C:\ColdFusion10\cfusion\wwwroot\
- Unzip the sample application files into the learncfinaweek folder. The contents of the folder should look like this:
Windows
Learn CF in a Week - Week 1 - Installation Page 9
- To confirm you have the files in the correct place go to: http://localhost:8500/learncfinaweek/.
- Now that you have the files in the correct place you now need to run an install script that will populate your database and set up ColdFusion with the necessary information. Go to: http://localhost:8500/learncfinaweek/install/.
- Fill out the form using the passwords from the previous installation processes and click on install.
Mac
- Download the sample application files from the download link in the header of http://www.learncfinaweek.com/.
- Create a folder in your web root called learncfinaweek. Your webroot is located at /Applications/ColdFusion10/cfusion/wwwroot/
- Unzip the sample application files into the learncfinaweek folder. The contents of the folder should look like this:
- To confirm you have the files in the correct place, go to: http://localhost:8500/learncfinaweek/.
- Now that you have the files in the correct place, you now need to run an install script that will populate your database and set up ColdFusion with the necessary information. Go to: http://localhost:8500/learncfinaweek/install/.
- Fill out the form using the passwords from the previous installation processes and click on "Install".
- If any problems occur, follow the onscreen instructions on how to correct them. If no problems exist, you are good to start the course.
Learn CF in a Week - Week 1 Page 8 The Basics By Dan Wilson
About Dan Wilson
As principal partner of DataCurl LLC, Dan Wilson runs both the consulting practice and ChallengeWave.com, a way to help employees start and stick with healthier lifestyles. Before launching DataCurl, Dan held numerous senior program and development positions in such industries as Technical Consulting, Health Care, Online Publishing and Government Contracting. Dan is an avid participant in technology communities; an Adobe Community Professional, manager of the Triangle ColdFusion User Group in Research Triangle Park, North Carolina, Managing Director of the popular Model-Glue framework and contributor to numerous open source projects based on ColdFusion, Flex and AIR platforms. Dan presents on ColdFusion, Flex and Rapid Development Techniques at popular conferences around the world. You can find his thoughts on ColdFusion, Flex, AIR and other technology matters at http://www.nodans.com and some occasional ramblings on food at http://blog.chefdanwilson.com. When not in front of a computer, you can find him biking, hiking, surfing, playing volleyball and helping small businesses improve their sales and marketing. 1
Learn CF in a Week - Week 1 Page 9 What is ColdFusion? ColdFusion is a rapid development platform for building modern web applications. ColdFusion is designed to be expressive and powerful. The expressive characteristic allows you to perform programming tasks at a higher level than most other languages. The powerful characteristic gives you integrations with functionality important to web applications like database access, MS Exchange access, PDF form creation and more. The ColdFusion platform is built on Java and uses the Apache Tomcat J2EE container. While you have full access to Java and Tomcat, you need not worry about these details. You'll interact with ColdFusion and the user friendly ColdFusion Mark-up Language (CFML) to write your programs. Your ColdFusion files will use the file extension '.cfc' for objects and '.cfm' for pages. CFML requires much less ceremony and infrastructure than typical java while offering a significantly faster development experience than Java. After taking this CF in a Week series, you'll have the basics necessary to begin making dynamic web sites, building intranet applications, or even working on the next Facebook competitor!
Learn CF in a Week - Week 1 Page 11 The Left Side Of The Statement: <cfset ThisIs The left side of the statement is the variable name. You can have numbers as part of the variable name, but the variable name must start with a letter. You must not have any spaces in your variable names. If you need to use more words for your variable name, you can simply write the variable with CamelCase letters, or use Under_Scores to separate each word if you want. The choice is one of style, there are no right answers. Also, most special characters are not allowed in variable names. A good rule to follow is variable names should be descriptive and help provide context to what is being done. For example, the word variable is a bad naming choice because the name adds no context to why the variable exists:
In the first statement, our math problem is surrounded by the Double Quote character. This tells ColdFusion to treat the statement as a string and do no evaluations on it. In the second statement, we also surrounded the math problem with the pound sign. ColdFusion executes the statement and performs our calculation for us. In the third statement, notice we've mixed strings and evaluations through the correct use of the pound sign and the double quotes. The variable name UserBirthdate is a good naming choice because it adds context to why the variable exists: Pro Tip: You'll understand the most about WHY your program is written a certain way as you are writing it. Take advantage of that hard-earned understanding and leave yourself (or others) as many clues and as much context as possible. Later on, after you've forgotten some of the details, it'll be much easier to piece together why the program was written a certain way and it'll be quicker to make good updates to your program. The Right Side Of The Statement: "fun"> The right side of the statement contains the value for the variable. Simple strings are enclosed in single or double quotes, with double quotes being the most common.
Learn CF in a Week - Week 1 Page 12 The right side of the statement is an execution zone. This means ColdFusion will attempt to evaluate items on the right side of the statement. Examples
Print Out the Current Date:
See how the ColdFusion function now(), which gets the servers current date and time, was evaluated and the contents placed in the variable DateToday? Anything not specifically in quotes (double or single) will be evaluated. It is possible to evaluate items in quotes, if you use the # sign. Keep this in mind as you develop ColdFusion. Novices have a tendency to overuse the pound sign.
Alternate Method: Print Out the Current Date:
This code will evaluate to the same thing in the previous step. Here are a few examples that will help you understand setting ColdFusion variables: However, unless there are strings in the quotes, it's generally preferred to use the previous method. To mix execution and strings, do this: Mix Execution and Strings Concatenation You could also concatenate the strings using the & operator. This example is functionally equal to the previous example: <cfset DateToday = "Today is: " & now() /> So is this one: