Copy link to clipboard
Copied
Hey there
[RPC Fault faultString="Unable to invoke CFC - Local variable currentUserVO on line 26 must be grouped at the top of the function body." faultCode="Server.Processing" faultDetail=""]
<cffunction name="login" displayname="login" access="remote" output="false" >
<cfargument name="userVO" required="true" type="CurrentUserVO">
<cfquery name="loginQuery" datasource="*">
SELECT * FROM user WHERE username= '#userVO.username#' AND password = '#userVO.password#'
</cfquery>
<cfloop query="loginQuery">
<cfset var currentUserVO=createObject("component","CurrentUserVO")>
<cfset currentUserVO.username = #loginQuery.username# >
<cfset currentUserVO.password = #loginQuery.password# >
<cfset currentUserVO.firstname = #loginQuery.firstname# >
<cfset currentUserVO.lastname = #loginQuery.lastname# >
<cfset currentUserVO.id = #loginQuery.id# >
<cfset currentUserVO.mail = #loginQuery.mail# >
<cfset currentUserVO.tel = #loginQuery.tel# >
</cfloop>
<cfif isDefined("currentUserVO")>
<cfreturn #currentUserVO#>
<cfelse>
<cfreturn 'false'>
</cfif>
</cffunction>
In the past( on my local mashine) it works correctly. But i'll test it on a real server and that error occours.... Is the Script not correct? (I'm a FlashDeveloper and to sooo familiar with Coldfusion)
Greetings, Nico
Hi Nico
Well... what does the error message actually say:
Local variable currentUserVO on line 26 must be grouped at the top of the function body.
And this is line 26:
<cfset var currentUserVO=createObject("component","CurrentUserVO")>
If you have a look at you other <cfset> statements, you'll see the difference here is the VAR keyword.
So, what do the docs say about the VAR keyword:
http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_29.html
(I found this page by looking up VAR in the i
...Copy link to clipboard
Copied
Hi Nico
Well... what does the error message actually say:
Local variable currentUserVO on line 26 must be grouped at the top of the function body.
And this is line 26:
<cfset var currentUserVO=createObject("component","CurrentUserVO")>
If you have a look at you other <cfset> statements, you'll see the difference here is the VAR keyword.
So, what do the docs say about the VAR keyword:
http://livedocs.adobe.com/coldfusion/8/htmldocs/buildingComponents_29.html
(I found this page by looking up VAR in the index of the docs):
"You must define all function local variables at the top of the function definition, before any other CFML code; for example: [etc]"
So your problem is that that VAR statement is NOT at the top of the function, as per the docs and the error message.
As to why it might have worked for you before? This restriction of where VAR statements go has been removed from CF9. So if you were using CF9 before, your code would have compiled OK. But not on CF6.1->CF8.
Make sense?
--
Adam
Copy link to clipboard
Copied
Ah... I've tried it with COldfusion 9 but our Server runs on Coldusion8 ....
But, i have to create a instance of that var for each user in the db - in the querryloop. How can i solve that problem?
Copy link to clipboard
Copied
Ah... I've tried it with COldfusion 9 but our Server runs on Coldusion8 ....
But, i have to create a instance of that var for each user in the db - in the querryloop. How can i solve that problem?
That's fine. One you've declared a variable to be function-local (using the VAR statement), it stays function-local for the life of the function. You don't have to re-state that it's function-local every time you use it.
So initialise it as a VAR @ the top of the function, then use it as per normal thereafter.
Make sense?
--
Adam
Copy link to clipboard
Copied
Jeah of course that makes sense, i would declare a variable on the top of the function in Actionscript, too.
But in As i call (in the loop) something like "myVar = new Var() .... array.push(myVar)" How can i do that "new MyVar" in Coldfusion? So it creaes an instance for every step in the loop.
Greets, Nico
Copy link to clipboard
Copied
But in As i call (in the loop) something like "myVar = new Var() .... array.push(myVar)" How can i do that "new MyVar" in Coldfusion? So it creaes an instance for every step in the loop.
But hang-on. Think about what you're saying here. One does not do this:
new myVar = SomeClass()
One does this:
myVar = new SomeClass()
Once the variable is declared, you don't re-declare it. You just re-set it if you need to.
In CF if you're dealing with components, the syntax is indeed:
myVar = new SomeCfc()
Or indeed one can use createObject() or <cfobject> to arrive at the same end (the new keyword is new to CF9).
But primitive types such as strings & structs and what not, there is no need to use the concept of the new keyword, because they are not objects in the CF sense of the idea. This is fine:
myVar = myOtherThing
--
Adam