Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Strange Error...

New Here ,
Oct 22, 2009 Oct 22, 2009

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

TOPICS
Flash integration
1.8K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Oct 22, 2009 Oct 22, 2009

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

...
Translate
LEGEND ,
Oct 22, 2009 Oct 22, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 22, 2009 Oct 22, 2009

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 22, 2009 Oct 22, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Oct 23, 2009 Oct 23, 2009

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2009 Oct 23, 2009
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources