URL Variables / Dynamic URL Variables
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com’s entire library of video tutorials.
Learn More
Subtitles of the Movie
What we're going to take a look at in this movie is passing Dynamic URL Variables, so if you have not viewed the Passing and Displaying URL Variables you may want to do that before watching this movie. I have two pages set up; I have one called dynamicPass and another called dynamicDisplay and I do have these two pages completed as dynamicDisplayDefined and dynamicPassDefined in the Set files if you'd rather look at the completed versions, but I'm going to walk you through this exercise. So the idea is the user puts this into their browser, they choose a favorite dessert, when they click on that favorite dessert the next page displays that specific one they chose. So how do we create that because we don't know what their dessert is at this point in time, we have no idea which hyperlink they're going to click on, so let's go into Code view and create the page to actually create the URL Variable, so I'm going to put a question mark and put dessert equals Pumpkin Pie and I'm going to use a plus sign as the space to avoid having to use the urlEncodedFormat function, just to make this a little bit easier. So, we're passing the dessert. I'm going to take that and copy it all the way down. So right after the m in cfm I'm going to copy that because the variable name is dessert, whatever dessert they click on we're going to display this as the URL Variable, so all I need to do is change it to the actual dessert and this one is known as the Sacher Torte, it's a very famous dessert in Austria. Next one, as you can see I'm using a plus sign as the space, New York plus Cheesecake and bear with me as I type these out. As I said, you can always go out and look at the completed versions, but the rest of this will come in real quick because I'm using Pie, so this one is French Silk Pie and the last one is Pecan. So this page is set up now. I've also surrounded this page with a cfoutput tag, which I really don't need to have in here so let me delete that. We don't need to play with that. If we were going to add ColdFusion code for the URLEncodedFunction we would want to add that. So, there is our page. Let's review it in the browser and you can see down at the bottom in this area right here you can watch Pumpkin plus Pie, Sacher plus Torte, New York Cheesecake - you can see they're all displaying correctly. I always double check this before I move on to the next page. So let's move over to the Display page and see what we need to do here. Well, all we need to do is put a pound sign and put URL. whatever the variable name is and we named it dessert. Now we do need a cfoutput in here to process this value out of URL.dessert, so I'm going to click the out in the CFML tab and just click OK and what that does is surround whatever I have selected with the cfoutput tag. Comes in very handy. Let's go ahead and run this and see what happens. Now you can see when I hover over it, it has the plus sign, but if I click Pumpkin Pie the next page says: My favorite dessert is Pumpkin Pie, Sacher Torte - we'll go right down the line - New York Cheesecake - it's as easy as that to pass data from one page to the next. Why would you want to use this? Well, if you go to a movie theatre website and you choose the movies you get a listing of movies. Think of this as your movie listing. You click on a movie, you go to the next page, it gives you all the details about that movie. Exact same concept. They're using a URL Variable to pass the ID for each movie here and then this page is actually querying the database for all of that information and we're going to do something similar in a later lesson when we get to working with the database portion of this course, but that is Dynamic URL Variables and working with them. Our variable has the same name, the value is different, it's being passed to the next page and we use it as a URL. whatever we named the variable. And we could display more than one variable on here just like we've done in the past in the Passing and Displaying URL Variables. So, that is working with Dynamic URL Variables.
Tutorial Information
| Course: | Adobe ColdFusion 8 |
| Author: | Candyce Mairs |
| SKU: | 34093 |
| ISBN: | 1-936334-05-4 |
| Release Date: | 2010-02-26 |
| Duration: | 8 hrs / 112 lessons |
| Work Files: |
Yes |
| Captions: | Available on CD and Online University |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |
VTC Sign up & Benefits
- Unlimited Access
- 98,729 Video Tutorials (23,265 free)
- Video Available as Flash or QuickTime
- Over 1026 Courses
- $30 for One Month Access
- Multi-User Discounts Available
United States 