Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can we have cfparam with positional attributes in script based style?

@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>

enter image description here

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 !.

like image 853
Kannan.P Avatar asked Mar 04 '23 05:03

Kannan.P


1 Answers

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#");
}
like image 102
rrk Avatar answered Mar 05 '23 18:03

rrk