Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member
I want to show you that ColdFusion does allow you the ability to call a ColdFusion component method, from outside your application or via the Internet and that's exactly what I'm going to do. So I'm using the bookingproperties.cfc and I'm going to call a method of this CFC, the one called list tours, from within the browser. So I won't be calling it from another ColdFusion page within my website. So I'll go out and do that.
What I need to do is plug in the URL in order to do that. And I have this somewhat setup in here so I'll go ahead and take advantage of that. And what I'm going to do is plug in local host, power workshop. That's my root folder. The booking folder, and the booking properties specifically. So you can see it's going right to this component.
And then, within the URL, I'm going to say method equals list tours. Now this method is the method right here that I'm going to be calling by hitting enter or return on my keyboard, and there is my method call. Now it does take a little bit of setup within your method in order to be able to do this. What I did, was I plugged this method output into a table just to make it look a little bit nicer for you when I went to run this tour. So let's go take a look at Booking Properties.
And take a look at that list tours that created this output. So, if I scroll down the page, list tours is down towards the bottom. And this is a new method that I added to the page. Notice that return type on this method is void. But I'm also setting it up access equals remote. Now if I try and call this method and it's not remote, let me put public in here, I'll save it and go back out and make a call once again.
And hopefully I have this in my history here and I do. You can see this component cannot be accessed remotely. I am trying to call it from outside my ColdFusion application, and it does not allow access of remote. So it does need to be access of remote, in order to be able to work with this. Now what I did was, I set a local variable, this is a new variable scope and it represents the scope for a function.
So, when I use local I can use this instead of saying var space. So, they're subtly different in terms of how they look and I think the local scope is much easier to work with. This is a new feature. So I'm setting that equal to all tours. What that's going to do is run the method, pull it into that variable, and then I'm going to output the content and notice I'm referencing it using that local variable.
And it's all just put in a table structure. The important piece is that you must have access of remote, in order to access it from a URL, but what you do is, call the component by its name and its path, put a question mark and then list the methods. If there were any arguments that needed to be passed into this method, I would simply put an ampersand, put the name of the argument, and an equals sign, equal to the value of that argument.
This one is a simplified example of working with that URL call to an instance method. But that is how you call the method of a component from a URL.
Get unlimited access to all courses for just $25/month.Become a member
61 Video lessons · 100164 Viewers
56 Video lessons · 113179 Viewers
71 Video lessons · 82040 Viewers
131 Video lessons · 39369 Viewers
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.