RandyLahey
RandyLahey

Reputation: 979

How to use cfparam for a structure in CF8?

I need to pass a structure to a method, but it will not always be defined.

Is there something like this that would work?

<cfparam name="system_message" default={}>

When I try this I get, the argument passed to the function is not of type struct.

Also, I realize, I could do this:

<cfif ! isdefined("system_message")>
      <cfset system_message = {}>
</cfif>

But I was just wondering if there was a shorter way of doing it, using cfparam.

Thanks for any help!

Upvotes: 3

Views: 972

Answers (3)

Dan A.
Dan A.

Reputation: 2924

If you are passing this to a method, you should consider using <cfargument> within a <cffunction> call rather than the more global <cfparam>. The same "default" attribute applies. Then you know your variable exists only within the ARGUMENT scope within the function, better encapsulation!

<cfargument name="system_message" default="#structNew()#">

Upvotes: 3

RobG
RobG

Reputation: 1821

What about:

<cfparam name="system_message" default="#StructNew()#">

CF8 doesn't like the curly braces version.

Upvotes: 9

Peruz Carlsen
Peruz Carlsen

Reputation: 582

You're close. You'll need to write it as:

<cfparam name="system_message" default="#{}#">

Upvotes: 3

Related Questions