@Devs, Here I'm writing the script based code for my application. While in a development I'm facing issue like Invalid CFML construct found
Sample Code :
<cfscript>
cfparam(name="userID", default=0); // Named attributes are accept in script based code.
cfparam("myName", 'Kannan'); // Without named attributes. It's return the error.
writeDump(userID);
writeDump(myName);
</cfscript>
I'm not sure whether the ACF allowed positional values ( without named parameter ) in cfparam or not in script based coding style.
FYR : We can use writedump like below
writeDump(var = userID);
writeDump(userID);
Both are returning same result. Not only writedump most of the building functions are support named attributes as well as positional attributes.
Likewise why cfparam not supported this things. Correct me if I did any mistake on my cfparam code or misunderstood anything.
Thanks in advance !.
Well, it is quite interesting to see how it works in the background by looking into the cfusion.jar
. Since I am not really a Java person, not quite sure my interpretation is right or not. Let me try though.
Inside cfscript
any function which starts with cf
are considered as a ColdFusion tag instead of a function.
What I see is that like cfparam
, you can use more functions(and more) as well.
cfquery
cfsavecontent
cfinclude
cfthrow
cfabort
I was kind of surprised to see the following syntax works in ColdFusion (I am not sure if there are any documentation that details this syntax).
<cfscript>
cfquery(name="test", datasource=application.dsn){
writeOutput('select * from user where userid = ');
cfqueryparam(value="1", cfsqltype='integer');
};
cfdump(var=test);
</cfscript>
So to wind up, same way you cannot define a ACF tag with out specifying name for the attribute, any function with in <cfscript>
starts with a coldfusion tag name will need named arguments.
Most likely this was implemented for CF9 or later version to get cfscript
support. Later versions has its independent implementations of each tag with out a prefix of cf
.
like
param name="test" default="";
savecontent variable="errortext" {
writeOutput("Application: #test#");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With