Request Events / OnRequest
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
We are going to look at the onrequest method in this movie, and this method operates very different from onrequest start and onrequest end, so this is one you want to use with caution. This method will actually run and replaces the actual page request. So instead of requesting my actual page, it will run this method instead. So what we're going to do is demonstrate that to you, put it to work so to speak. So it returns no value. One argument is passed in, just like the others, the actual page that's being requested and what I have this doing is actually outputting to the page some text and I do have an include in here including the actual page that was being requested. So I think this one's easiest to see in action. Woops. I want to copy this code. From that I'll move over to the application.cfc and I will put this under the onrequest start and onrequest end methods. Just make sure any methods go inside that closing cfcomponent tag or you will have some issues. So what I have done is have this test page and you can see it's the same page we used for onrequest and has some code on here. Let's see what happens now that we've added onrequest. I will preview this in the browser and you can see what happened. Onrequest start pulled in the header. This section here was pulled in by the onrequest method. Actual page code did not run right here, so you have to be careful when this method is used. What I did at that point was added a cfinclude to include my test page. So I will remove that and you'll see what ended up happening. So the onrequest method added this information, the include within that method added the header, the main portion of the page and the footer. So we actually have four different things being included on this same page. To show you exactly what I'm talking about, what I will do is go back to my application.cfc and I will eliminate, I will just comment out this include file and then you will see that the actual page code no longer runs. What will run is the information and it looks like we are having an error. So let's take a look at what's going on. And I eliminated the include, this information is being output so let's see. We are here. Let's run that test page one more time. So the onrequest start is going to try and run and there we are. I thought it just didn't refresh. So what happened is this is being pulled in by the onrequest start, this is being pulled in by the onrequest end and this middle section is being pulled in by the onrequest. And I like to show you this because this is the sequence they are run within your page code. So onrequest start runs, then onrequest method runs, then onrequest end. So you can see and play around with this a little bit so you fully understand the onrequest method. The first time through, our browser just didn't refresh. But notice the page code for the test page itself, even though it shows it up here, none of that code is showing and I'll show you what I mean by that. This information here is not showing up at all on my page. So it has replaced the actual page code. In order to get to that to show again, I can uncomment this template here. That will allow all of it to run. So the onrequest start, let's refresh that once more. And I'm not sure why that doesn't like to refresh, but oh, I'm sorry. I'm running the application.cfc. No wonder. I'm glad I showed you that. Ok. We'll go back to test page and there we are. So we have our onrequest start bringing in the header, our onrequest method bringing in the information, then the onrequest method pulls in our page code, which is actually what added the header, the footer and this information. So just make sure you do not try and call the application.cfc file directly from your browser because it doesn't work. And I do like to show some of these errors once in a while. You can still get caught on some of this stuff as you go through. So don't panic if you see errors. Just think through, ok, what might have caused the error and read the error information. So that is the onrequest method. What we need to do is make sure we go back and we're going to comment out this lower portion of this method as well; otherwise that's going to run on every page request and we don't want to see that code. So just make sure you comment out the rest of the onrequest method before you move on to the next movie.
Tutorial Information
| Course: | ColdFusion MX 7 Advanced |
| Author: | Candyce Mairs |
| SKU: | 33828 |
| ISBN: | 1-934743-34-8 |
| Release Date: | 2007-11-30 |
| Duration: | 6 hrs / 89 lessons |
| Work Files: |
Yes |
| Captions: | For Online University members only |
| 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 