Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

passing variables to cfc method

New Here ,
Jul 13, 2008 Jul 13, 2008
Hi

I've just written my first couple of cfcs, and passed the variables to the methods using the cfinvoke attributes. This doesn't seem to require the cfargument (ie the method works for me and I haven't used cfargument).

So I must admit that I'm a bit confused about what the point of the cfargument tag is, exactly? What will go wrong if I don't use it?

Many thanks

Dave S
TOPICS
Getting started
10.0K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 13, 2008 Jul 13, 2008
Methods can either contain cfargument or not. They can be required or not required. Since your method doesn't have cfarguments, then your method does not require any variable inputs(cfarguments) which will work fine.

You only need cfargument if your method needs to accept variables(required or not required) and process those variables. There are lot of uses in putting cfarguments and a lot of reasons depending on the programmer and process/application you are trying to achieve. Example, if you are trying to create a cfc for arithmetic and inside that cfc is a method that adds numbers, how will your method know what numbers to add if you don't pass variable inputs(that will be received by cfarguments)? But if your process doesn't require to process any input variables, then there is no need for cfarguments, and definitely no need for passing variables to your method(in cfc) which does not even receive one. Take note that methods are actually functions, and functions can either take arguments or not. This concept is common to all scripting and programming languages.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 13, 2008 Jul 13, 2008
Hi
thanks for that answer. But what seems to be the case to me is that variables can be processed in a method without having cfargument to accept them - I think I must be misunderstanding something somewhere.

Eg in my "beginners" component I have the following on a cfm template and on a cfc, the first passes a variable to the second but I haven't used cfargument:


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jul 13, 2008 Jul 13, 2008
all very good questions, I'm interested to hear what the gurus say as well on that one daveioi
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 13, 2008 Jul 13, 2008
> So I must admit that I'm a bit confused about what the point of the cfargument
> tag

Have you read the docs for <cfargument>? That's always a good place to
start when trying to find out what something does.

http://livedocs.adobe.com/coldfusion/8/Tags_a-b_6.html

In short, <cfargument> has these benefits:
- enables type validation on arguments;
- enables requiredness validation on arguments;
- enables the provision of default values for optional arguments;
- enables the creation of API documentation for your CFCs (and, indeed,
code self-documentation);
- enables the definition of an interface for overridden CFC definitions;
- enables the definition of web services (or at least allows one to defined
web services that take arguments, anyhow).

--
Adam
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jul 14, 2008 Jul 14, 2008
Thank you for that, it answers my question - ie it's necessary in some cirumstances, very useful in others but perhaps not necessary in yet other circumstances.

Dave
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Sep 03, 2008 Sep 03, 2008
LATEST
Actually good programming practice says you will use it all the time to prevent unwanted code from comiing in disguised as your form field.

Ever hear of sql injection attacks? If you are not validating input data you are open to such attacks.

ALWAYS know what is coming in to your programs. cfarguments at least verify that it is the proper type.
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources