0
passing variables to cfc method
New Here
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/td-p/170762
Jul 13, 2008
Jul 13, 2008
Copy link to clipboard
Copied
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
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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170763#M15554
Jul 13, 2008
Jul 13, 2008
Copy link to clipboard
Copied
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
daveioi
AUTHOR
New Here
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170764#M15555
Jul 13, 2008
Jul 13, 2008
Copy link to clipboard
Copied
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:
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:
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Participant
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170765#M15556
Jul 13, 2008
Jul 13, 2008
Copy link to clipboard
Copied
all very good questions, I'm interested to hear what the
gurus say as well on that one daveioi
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
LEGEND
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170766#M15557
Jul 13, 2008
Jul 13, 2008
Copy link to clipboard
Copied
> 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
> 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
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
daveioi
AUTHOR
New Here
,
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170767#M15558
Jul 14, 2008
Jul 14, 2008
Copy link to clipboard
Copied
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
Dave
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more
Contributor
,
LATEST
/t5/coldfusion-discussions/passing-variables-to-cfc-method/m-p/170768#M15559
Sep 03, 2008
Sep 03, 2008
Copy link to clipboard
Copied
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.
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.
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting.
Learn more

