question about cfc perfomance
Hi to ALL!!!
I have some pages with <form> tag and I have SEVERAL <input> tags, wich may repeate (present) in all of this <forms>. I'm trying to do efficient validation (in my case, EFFICIENT means - optimize in memory and cpu usage)
So thirst , I've made validation.cfc, wich inclueds ALL validation rules (about 30 rules) for ALL inputs, and it looks like
METHOD #1
<cfscript>
function Valid() {
var arErrorlist=arraynew(1);
if (structkeyexists(form,"input1")){
some code - if it's true,then - arrayappend(arErrorlist,"error mesage 1")
}
if (structkeyexists(form,"input2")){
some code - if it's true,then - arrayappend(arErrorlist,"error mesage 2")
}
....................
if (structkeyexists(form,"input30")){
some code - if it's true,then - arrayappend(arErrorlist,"error mesage 30")
}
return arErrorlist;
}
</cfscript>
So, on action page I have:
<cfscript>
request.one=createobject("component",validation);
request.two=request.one.validation();
</cfscript>
If something wrong - I have request.two with arErrorlist
But I think, this method is BAD, because if I check a form with only 3 inputs, server have to parsing ALL 30 "if (structkeyexists(form,"input N "))"
In other hand I can use validation.cfc , wich can look like
METHOD #2
<cfscript>
this.arErrorlist=arraynew(1);
function check_input1 () {
some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 1")
}
function check_input2 () {
some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 2")
}
....................
function check_input30 () {
some code - if it's true,then - arrayappend(this.arErrorlist,"error mesage 30")
}
</cfscript>
And action page can be:
<cfscript>
request.one=createobject("component",validation);
request.one.check_input N //what actualy need on current form
.........
request.one.check_input N //what actualy need on current form
</cfscript>
If something wrong - I have request.one.arErrorlist
And finaly (METHOD #3) I can use on action page cfc with "extend" to validation.cfc from method #2
So, what do you think - wich method - #1, #2 or #3 will be more efficient?
Thanks for your answers!!!
